jquery置顶栏

2013-8-24 chenmo 网页设计

又找到了这个小功能。还有footer固定的
<html>
    <head>
    	<script src="jquery-1.9.1.min.js"></script>
	</head>

    <body>
    	<script>
    $.fn.smartFloat = function() {
	    var position = function(element) {
	        var top = element.position().top, pos = element.css("position");
	        $(window).scroll(function() {
	            var scrolls = $(this).scrollTop();
	            if (scrolls > top) {
	                if (window.XMLHttpRequest) {
	                    element.css({
	                        position: "fixed",
	                        top: 0
	                    });    
	                } else {
	                    element.css({
	                        top: scrolls
	                    });    
	                }
	            }else {
	                element.css({
	                    position: "absolute",
	                    top: top
	                });    
	            }
	        });
	    };
    	return $(this).each(function() {
        	position($(this));                         
    	});
	};
    	</script>
    <script>
    $(function(){	
	$(".caseMenu").smartFloat();	  
	})
    </script>
    <style>
    html,body{margin:0px; height:0px;}
    .caseMenu{background: #000; width:100%; color:#fff; text-align: center; height:45px; line-height: 45px; font-family: microsoft yahei; letter-spacing: 2px; font-size: 18px; position:fixed;top: 0}
    p{height:400px;}
    .main div{width:100%; height:300px;}
    </style>
    <div class="caseMenu">置顶栏</div>
    <div class="main">
    	<div style="background:#5EEAFF"></div>
    	<div style="background:#FF985E"></div>
    	<div style="background:#FF5EEC"></div>
    	<div style="background:#FFDD5E"></div>
    	<div style="background:#FAFFE3"></div>
    	<div style="background:#E7ECE7"></div>
    	<div style="background:#C7CCA9"></div>
    	<div style="background:#FAC5CC"></div>
    	<div style="background:#F88795"></div>
    	<div style="background:#6E526A"></div>
    </div>
    </body>
</html>

标签: jQuery 置顶栏

Powered by emlog 湘ICP备13007859号 空间由景安网络赞助