zoukankan      html  css  js  c++  java
  • 简易的jquery层随滚动条移动

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>简易的jquery层随滚动条移动</title>
    <script type="text/javascript" src="jquery.js"></script>
    </head>
    <style>
    body{ padding:0;margin:0;}
    .main{ width:1000px; background:#FFCCFF; height:2000px; margin:0 auto; position:relative;}
    .divScroll{ width:100px; height:150px; background:#FFFF99; padding:15px;position:absolute; top:50px; left:50%;margin-left:500px;}
    </style>
    <body>
    <div class="main">
    <div class="divScroll">滚动层</div>
    </div>
    <script>
    $(window).scroll(function(){
    invertal=setTimeout(function(){            //定时start,加定时可以防止层抖得太厉害
    var vtop=$(document).scrollTop();
    if(vtop>20){                            //如果滚动大于20像素
    $(".divScroll").css("top",vtop+"px");
    }
    },300)                                    //定时end,300是时间
    })
    </script>
    </body>
    </html>

    效果图:黄色层随滚动条滚动

    没滚动时:

    滚动后:

  • 相关阅读:
    关于 js 下载PDF文件时
    vue3.0 学习
    iOS
    bootstrap treeview
    SVN版本管理
    js框架
    正则表达式
    如何让安卓手机在电脑上同步显示(MX4 Pro为例)
    mysql 中文乱码
    ADO.NET 数据库连接池大小
  • 原文地址:https://www.cnblogs.com/tinyphp/p/3119400.html
Copyright © 2011-2022 走看看