• 跟随屏幕滚动层、遮罩层、获取Div相对定位、整个屏幕、html文档的jquery基本操作


    一、层跟随屏幕滚动

           <div style="120px;height:120px;border:1px solid red; position:absolute; left:800px; top:100px; z-index:1001;" id="AdminUserStateDiv">
            
            </div>
            <div class="div1">层1</div>
            <div class="div2">层2</div>

     <style type="text/css">
            .div1{
        background-color:#FF0000;
        2000px;
        height:2000px;
        }

        .div2{
        background-color:#33FF66;
        100px;
        height:100px;
        position:fixed;
        left:50px;
        top:50px;
        }
        </style>

    <script>

        (1)对文档、屏幕、层的一些jquery基本操作

    var showAdminUser = function (obj) {
            var offSet = $(obj).offset();
            var docTop = offSet.top;    //当前元素相对文档top偏移位置
            var docLeft = offSet.left;  //当前元素相对文档left偏移位置

            var docWidth = $(document).width(); //整个页面文档的宽度
            var docHeight = $(document).height();   //整个页面文档的高度
            var dScrollTop = $(document).scrollTop(); //整个文档滚动条相对top位置
            var wScrollTop = $(window).scrollTop(); //整个屏幕滚动条相对top位置
            var winWidth = $(window).width(); //整个屏幕宽度
            var winHeight = $(window).height();//整个屏幕高度

            alert("docWidth: " + docWidth + "——" + "docHeight:" + docHeight + " dScrollTop:" + dScrollTop);


            var dWidth = document.body.offsetWidth;  //纯javascript整个页面文档的宽度
            var hHeight = document.body.offsetHeight;   //纯javascript整个页面文档的高度
            var scrollTop = document.body.scrollTop + document.documentElement.scrollTop
            alert(" docWidth: " + dWidth + " docHeight: " + hHeight + " : " + scrollTop);

        }

      (2)层伴随滚动条
        $(document).ready(function () {

            $(window).scroll(function () {

                var scrollTop = $(document).scrollTop(); //htm文档滚动对象距离顶部位置
                //alert(scrollTop);

                var AdminUserStateDiv = $("#AdminUserStateDiv");
                //AdminUserStateDiv.css("top", scrollTop + "px");
                AdminUserStateDiv.animate({ "top": scrollTop + "px" }, 0);  //层伴随滚动条滚动,时时改变层对顶部的距离
                //$("#scrollUl").animate({ "marginLeft": scrollposition + "px" }, 10);

            })
        });

    </script>

    (3)遮罩层和加载图片效果

        <div id="CommonAlertMessageBackg" style="display: none; height: 100%; left: 0; margin: 0; opacity: 0.7; position:absolute; top: 0; visibility: visible; 100%; z-index: 998; "> </div>  //解释:position:absolute;是固定在屏幕上;position:fixed;是系在屏幕上,跟随着滚动条移动的;


        <div id="loadding" style="display: none; position: absolute; z-index: 999;">
            <img src="@Url.Content("~/Content/img/loading3.gif")" alt="加载中......" />
        </div>

    <script type="text/javascript">
        var ShowLoadding = function () {
            var width = $(window).width();
            var height = $(window).height();
            $("#loadding").css("left", width / 2);
            $("#loadding").css("top", height / 2);
            $("#loadding").show();

            var top = $("#ListContent").offset().top;
            var left = $("#ListContent").offset().left;
            var width = $("#ListContent").width();
            var height = $("#ListContent").height();
            $("#CommonAlertMessageBackg").css({ "top": top, "left": left, "width": width, "height": height });

            $("#CommonAlertMessageBackg").show();
        };
        var HideLoadding = function () {
            $("#loadding").hide();
            $("#CommonAlertMessageBackg").hide();
        };

    </script>

  • 相关阅读:
    POJ 3373 Changing Digits 记忆化搜索
    POJ 3268 Silver Cow Party (Dijkstra + 优先队列)
    ZOJ 1232 Adventure of Super Mario (Floyd + DP)
    POJ 2406 Power Strings KMP算法之next数组的应用
    POJ 1961 Period KMP算法之next数组的应用
    POJ 2492 A Bug's Life 并查集的应用
    POJ 1703 Find them, Catch them 并查集的应用
    POJ 3321 Apple Tree 树状数组+DFS
    POJ 3368 Frequent values 线段树与RMQ解法
    POJ 3264 Balanced Lineup RMQ ST算法
  • 原文地址:https://www.cnblogs.com/BluceLee/p/4159447.html
Copyright © 2020-2023  润新知