电商鼠标滚动楼层显示

<!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{ width:1000px; height:500px; background:red; margin:0 auto;}
.first,.second,.three,.four {width:1000px;  margin:0 auto; height:800px; margin-top:20px; background:#0FF;}
.fixBox { width:50px; position:fixed; _position:absolute; _bottom:30%; _left:5%; _top:expression((offsetParent.scrollTop)+50); bottom:30%; left:5%; height: atuo;}
.fixBox ul { width: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:代码还可以优化~~

posted @ 2015-06-17 14:12  前端_茂  阅读(412)  评论(0编辑  收藏  举报