前端自制设备模拟器模拟不同终端展示效果

效果图

设备图片

图标

代码

html 复制代码
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,user-scalable=no,minimum-scale=1,maximum-scale=1">
    <title>多终端响应式项目开发,效果展示</title>
    <style>
        html,
        body,
        ul,
        li,
        p {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        html,
        body {
            width: 100%;
            height: 100%;
        }

        .top {
            width: 100%;
            height: 50px;
            background-color: #000;
        }

        .top .top-body {
            height: 50px;
            display: flex;
            align-items: center;
            max-width: 1000px;
            margin: 0px auto;
        }

        .top .top-body .screen-type {
            color: orange;
            /* flex-grow: 1; */
            padding-left: 50px;
        }

        .top .top-body ul {
            display: flex;
            align-items: center;
        }

        .top .top-body ul li {
            margin: 0px 5px;
            width: 17px;
            height: 16px;
            cursor: pointer;
        }

        /* pc 电脑 */
        li.pc {
            background: url(./images/mon-spr.png) no-repeat 0 0;
        }

        li.pc.active,
        li.pc:hover {
            background-position: 0 -16px;
        }

        /* ipad-v 平板-垂直 */
        li.ipad-v {
            background: url(./images/mon-spr.png) no-repeat -24px 0;
        }

        li.ipad-v.active,
        li.ipad-v:hover {
            background-position: -24px -16px;
        }

        /* ipad-v 平板-水平 */
        li.ipad-l {
            background: url(./images/mon-spr.png) no-repeat -49px 0;
        }

        li.ipad-l.active,
        li.ipad-l:hover {
            background-position: -49px -16px;
        }

        /* iphone 手机-垂直*/
        li.iphone-v {
            background: url(./images/mon-spr.png) no-repeat -71px 0;
        }

        li.iphone-v.active,
        li.iphone-v:hover {
            background-position: -71px -16px;
        }

        /* iphone 手机 - 水平 */
        li.iphone-l {
            background: url(./images/mon-spr.png) no-repeat -94px 0;
        }

        li.iphone-l.active,
        li.iphone-l:hover {
            background-position: -94px -16px;
        }

        #iframe-wrap {
            box-sizing: border-box;
            /* position: relative; */
            margin: 0px auto;
            background-size: cover;
        }

        #iframe-wrap iframe {
            overflow: hidden;
        }

        /* PC端 */
        .full-width {
            width: 100%;
            height: 100%;
        }

        .wrap-body {
            width: 100%;
            height: 100%;
            border-radius: 0px 0px 30px 30px;
            overflow: hidden;
        }

        /* 平板竖屏*/
        .tablet-width-v {
            width: 663px;
            height: 962px;
            padding: 28px 22px 28px 28px;
            background: url("./images/ipad-v.png") no-repeat;
        }

        /* 平板横屏 */
        .tablet-width-l {
            margin-top: 50px !important;
            width: 962px;
            height: 663px;
            padding: 24px 28px 24px 29px;
            background: url("./images/ipad-l.png") no-repeat;
        }

        /* 移动端竖屏 */
        .mobile-width-v {
            padding: 58px 42px 28px 44px;
            height: 884px;
            width: 496px;
            /* margin-top: 55px !important; */
            background: url("./images/iphone-v.png") no-repeat;
        }

        /* 移动横屏 */
        .mobile-width-l {
            height: 496px;
            width: 884px;
            padding: 42px 48px 40px 20px;
            margin-top: 80px !important;
            background: url("./images/iphone-l.png") no-repeat;
        }

        .mobile-width-l .wrap-body {
            border-radius: 30px;
        }
    </style>
</head>

<body>
    <div class="top">
        <div class="top-body">
            <ul id="J_icon">
                <li class="pc active" data-myclass="full-width" data-title="电脑端展示效果"></li>
                <li class="ipad-v" data-myclass="tablet-width-v" data-title="平板垂直展示效果"></li>
                <li class="ipad-l" data-myclass="tablet-width-l" data-title="平板水平展示效果"></li>
                <li class="iphone-v" data-myclass="mobile-width-v" data-title="手机垂直展示效果"></li>
                <!-- <li
            class="iphone-l"
            data-myclass="mobile-width-l"
            data-title="手机水平展示效果"
          ></li> -->
            </ul>
            <div class="screen-type" id="J_screen-type">电脑端展示效果</div>
        </div>
    </div>
    <div id="iframe-wrap" class="full-width">
        <div class="wrap-body">
            <!-- <iframe src="./index.html" frameborder="0" width="100%" height="100%" style="overflow: hidden"></iframe> -->
            <iframe src="https://v3.bootcss.com/" frameborder="0" width="100%" height="100%"
                style="overflow: hidden"></iframe>
        </div>
    </div>

    <script type="text/javascript">
        // 显示内容容器
        const iframeWrap = document.getElementById("iframe-wrap");
        // 图标列表
        const list = document.querySelectorAll(".top-body ul li");
        // 图标列表的父容器
        const oUl = document.getElementById("J_icon");
        // 屏幕类型显示文本
        const screenType = document.getElementById("J_screen-type");
        // 事件代理
        oUl.addEventListener("click", function (e) {
            const target = e.target;
            if (target.tagName.toLowerCase() !== "li") return;
            const myclassName = target.dataset.myclass;
            iframeWrap.className = myclassName;
            screenType.innerText = target.dataset.title;
            for (i = 0; i < list.length; i++) {
                list[i].classList.remove("active");
            }
            target.classList.add("active");
        });
    </script>


</body>

</html>
相关推荐
世界哪有真情3 小时前
拿人类意识卡 AI?等于用 bug 验收正式产品
前端·人工智能·后端
Listen·Rain4 小时前
Vue3:setup详解
前端·javascript·vue.js
Patrick_Wilson5 小时前
修好 bug 只是开始:一次由监控需求反向重构日志结构的复盘
前端·监控·数据可视化
kyriewen5 小时前
面试官让我优化一个卡死的表格,我打开 Claude 五秒重写,他放下咖啡问我要不要来当组长
前端·javascript·面试
‘’林花谢了春红‘’5 小时前
小玩意 生日快乐
css·html·css3
小粉粉hhh6 小时前
React(二)——dom、组件间通信、useEffect
前端·javascript·react.js
Csvn6 小时前
🤖 AI 生成前端代码的 5 个典型翻车现场及修复指南
前端
IT_陈寒7 小时前
SpringBoot自动装配坑了我一天,原来问题出在这
前端·人工智能·后端
索西引擎8 小时前
【React】key 属性:协调算法中的元素标识机制与最佳实践
前端·javascript·react.js
只会cv的前端攻城狮8 小时前
动态组件架构设计:从配置到事件驱动全链路解析
前端·vue.js