当前位置:   article > 正文

html5页面分屏 还有上下拖动_html创建一个可移动和缩放的分屏页面

html创建一个可移动和缩放的分屏页面

用到的框架

app框架

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link href="/views/share/css/mui.min.css" rel="stylesheet"/>
    <link href="/views/share/css/app.css" rel="stylesheet"/>
    <style>
        html,body{
            margin:0;
            padding:0;
            width: 100%;
            height: 100%;
        }

        .tabBoxBtn{
            background: url(/views/share/images/icon_data.svg) no-repeat;
            background-size: 100%;
            margin: 0 auto;
            width: 60px;
            height: 40px;
            display: block;
            top: -30px;
            position: relative;
            z-index: 99;
        }
        .type-title {
            position: fixed;
            width: 100%;
            margin: 0;
            line-height: 45px;
            color: #85b804;
            border-bottom: 1px solid #ddd;
            padding: 2px 10px;
            z-index: 999999;
            background: #f0f0f0;
        }
        .mui-slider-group55{
            margin-top: 45px;
        }
        .tabBox {
            height: 10px;
            display: block;
            position: fixed;
            top: 37%;
            width: 100%;
            box-shadow: 5px -4px 5px rgba(153, 153, 153, 0.54);
            z-index: 999999;
            background-color: #F0F0F0;
        }
        .topBox {
            height: 35%;
            /*margin-bottom: 1px;*/
            overflow-y: scroll;
        }
        .clear{
            clear: both;
        }
        .contentBox {
            height: 65%;
            overflow-y: scroll;
        }

        .bodyBox {
            height: 100%;
        }
        .boxIframe{
            margin-top: 18px;
            height: 95%;
            overflow-y: scroll;
        }
        iframe {
            width: 100%;
            height: 100%;
            /*background: #000;*/
        }
        .nameBox {
            padding: 10px!important;
        }
        .nameBox p{
            text-align: justify!important;
            text-justify: inter-ideograph!important;
            color: #000!important;
        }
    </style>
</head>
<body>
<div class="mui-content back-color-fff bodyBox">
    <div id="topBox" class="mui-row  topBox">
        <div class="mui-row type-title f14">
            <div class="mui-col-xs-6 mui-text-left">阅读材料</div>
        </div>
        <div class="mui-slider-group55">
            <div class="nameBox">
                <p class="f16">
                    ${bTestpaper.name}
                </p>
            </div>
        </div>
    </div>

    <div class="clear"></div>
    <div id="contentBox" class="contentBox">
        <div class="mui-row">
            <div class="tabBox" id="tabBox"><a href="javascript:;" class="tabBoxBtn" id="dragBtn"></a></div>
        </div>
        <div class="clear"></div>
        <div id="boxIframe" class="mui-row boxIframe">
            <iframe id="testpaperStuff" onload="loading()" src="/share?id=${sid}&PaperType=1" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"
                    allowtransparency="yes">

            </iframe>
        </div>
    </div>
</div>
<script src="/views/share/js/jquery.min.js"></script>
<script src="/views/share/js/mui.min.js"></script>
<script src="/views/share/js/footer.js"></script>
<script>
    loading();
    var clientHeight  = document.documentElement.clientHeight;
    //拖动
    var dragBtn = document.getElementById("dragBtn");
    dragBtn.addEventListener("dragstart",function (e) {
//        dragIndex = 0;
    });
    dragBtn.addEventListener("drag",function (e) {
//       console.log(e);
        var detail = e.detail;
        var direction = detail.direction;
        var deltaY = detail.deltaY;
        deltaY = Math.abs(deltaY);
        deltaY = 6;
        var maxLen = 50;
        var maxHeight = clientHeight - maxLen;
        var divTopHeight = clientHeight*0.022;
        var divTop = $("#topBox").height()+divTopHeight;
        if(direction=="down"){
            var topBoxAdd = $("#topBox").height()+deltaY;//上面div
            var contentBoxDel = $("#contentBox").height()-deltaY;//下面div
            topBoxAdd = topBoxAdd>maxHeight? maxHeight:topBoxAdd;
            contentBoxDel = contentBoxDel<maxLen? maxLen:contentBoxDel;
            $("#topBox").height(topBoxAdd);
            $("#contentBox").height(contentBoxDel);

            divTop = divTop>maxHeight?maxHeight+divTopHeight:divTop;//拖动按钮
        }
        if(direction=="up"){
            var topBoxDel = $("#topBox").height()-deltaY;//上面div
            var contentBoxAdd = $("#contentBox").height()+deltaY;//下面div
            topBoxDel = topBoxDel<maxLen? maxLen:topBoxDel;
            contentBoxAdd = contentBoxAdd>maxHeight? maxHeight:contentBoxAdd;
            $("#topBox").height(topBoxDel);
            $("#contentBox").height(contentBoxAdd);

            divTop = divTop<maxLen?maxLen:divTop;//拖动按钮

        }
//        console.log(divTop);
        $("#tabBox").css("top",divTop+"px");

    });
    dragBtn.addEventListener("dragend",function (e) {
//        console.log(e);
    });
    //拖动 end
    function loading(){
        $("#testpaperStuff").height(clientHeight);
    }

</script>
</body>
</html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177

滚动div监听

iframe的脚本

 var fu = window.parent.document;
        $("#boxIframe",fu).scroll(function () {
            var scrollTop = $(this).scrollTop();
            var scrollHeight = $(document).height();
            var windowHeight = $(this).height();
            if (askPage <= totalPage && askPage > 2) {
                if (scrollTop + windowHeight + 80 > scrollHeight) {
                    if (is_scroll) {
                        $("#answerBox").append("<p id='loading' style='text-align: center;background: #FFFFFF;padding-top: 1px;'> 正在加载...</p>");
                        showAsk();
                    }
                }
            }
        });
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

iframe高度自适应

在iframe的脚本

//iframe 的高度
function loadIFrame (){
    var fu = window.parent.document;
    var height = $("#testpaperStuff",fu).height();
    //console.log(height);
    if(height!=null&&height-10<$("html").height()){
        $("#testpaperStuff",fu).height($("html").height());
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

对ios不兼容 不用看了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/97440
推荐阅读
相关标签
  

闽ICP备14008679号