• 跟随屏幕滚动层、遮罩层、获取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>

  • 相关阅读:
    Java WebService异构系统通信的原理及特点:SOAP与WSDL
    jenkins下拉框选择构建环境
    vue中的hash与history
    一行代码轻松搞定企微内嵌h5调用原生api不生效问题
    开源绘图工具plantUML入门教程(常用于画时序图等)
    什么是持续集成、持续交付、持续部署(CI/CD)?
    一篇文章了解CI/CD管道全流程
    开源免费的SSH工具推荐:electerm(推荐)、Finalshell
    Oracle数据库设置表空间自动扩展(解决因表空间不足引起的ORA01653: unable to extend table错误)
    测试工作中浏览器F12工具简单使用介绍
  • 原文地址:https://www.cnblogs.com/BluceLee/p/4159447.html
Copyright © 2020-2023  润新知