zoukankan      html  css  js  c++  java
  • 电商鼠标滚动楼层显示

    <!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=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    *{ margin:0; padding:0;}
     body{ _background-attachment:fixed; _background-image:url(about:blank);}/*实现IE6不兼容fixed闪动问题*/
    .header{ 1000px; height:500px; background:red; margin:0 auto;}
    .first,.second,.three,.four {1000px;  margin:0 auto; height:800px; margin-top:20px; background:#0FF;}
    .fixBox { 50px; position:fixed; _position:absolute; _bottom:30%; _left:5%; _top:expression((offsetParent.scrollTop)+50); bottom:30%; left:5%; height: atuo;}
    .fixBox ul { 50px; height:100px;}
    .fixBox ul li { list-style:none; height:30px; line-height:30px; background:#ccc; text-align:center;}
    .fixBox ul li.show{ background:#F63;}
    </style>
    <script src="http://sz189.cn/promotion/js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function(){
        var first=$(".first").offset().top;
        var second=$(".second").offset().top;
        var three=$(".three").offset().top;
        var four=$(".four").offset().top;
        $(window).scroll(function(){
            if($(this).scrollTop() <=first){
                $(".show1").addClass("show").siblings().removeClass("show");
            }else if($(this).scrollTop() >=first&&$(this).scrollTop()<=second){
                $(".show2").addClass("show").siblings().removeClass("show");
            }else if($(this).scrollTop()>=second&&$(this).scrollTop()<=three){
                $(".show3").addClass("show").siblings().removeClass("show");
            }else if($(this).scrollTop()>=three && $(this).scrollTop()<=four){
                $(".show4").addClass("show").siblings().removeClass("show");
            }
        });    
    });

    </script>
    </head>

    <body>
    <div class="header"></div>
    <div class="first"></div>
    <div class="second"></div>
    <div class="three"></div>
    <div class="four"></div>

    <!--右侧导航-->
    <div class="fixBox">
        <ul>
            <li class="show1">1</li>
            <li class="show2">2</li>
            <li class="show3">3</li>
            <li class="show4">4</li>
        </ul>
    </div>

    </body>
    </html>

    ps:代码还可以优化~~

  • 相关阅读:
    学习进度笔记4
    学习进度笔记3
    学习进度笔记2
    学习进度笔记1
    《梦断代码》提及文献
    《梦断代码》阅读笔记6
    《梦断代码》阅读笔记5
    需求征集系统开发进度5
    《梦断代码》阅读笔记4
    spark filter
  • 原文地址:https://www.cnblogs.com/qdmaomao/p/4583169.html
Copyright © 2011-2022 走看看