zoukankan      html  css  js  c++  java
  • javascript实现页面悬浮导航

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    	a{
    		text-decoration: none;
    	}
    	#suspendNavigation{
    		position:absolute;
    		top: 0px;
    		left:0px;
    		background-color: #ccc;
    		 100%;
    		z-index: 1000;
    	}
    	#suspendNavigation div{
    		float: left;
    		position: relative;
    		border: #cc2123 1px solid;
    		19%;
    		height:30px;
    		text-align: center;
    		line-height: 30px;
    	}
    	body{
    		height: 2000px;
    	}
    </style>
    </head>
    <body>
    	<div id="suspendNavigation">
    		<h2>页面悬浮导航</h2>
    		<div>
    			<a href="" target="_blank">导航1</a>
    		</div>
    		<div>
    			<a href="" target="_blank">导航2</a>
    		</div>
    		<div>
    			<a href="" target="_blank">导航3</a>
    		</div>
    		<div>
    			<a href="" target="_blank">导航4</a>
    		</div>
    		<div>
    			<a href="" target="_blank">导航5</a>
    		</div>
    	</div>
    </body>
    <script type="text/javascript">
    	window.onload=function(){
    		//获取待定位的元素
    		var suspendNavigation=document.getElementById("suspendNavigation");
    		window.onscroll=function(){
    			//alert("test1");
    			//alert(suspendNavigation.style.top);
    			//alert(document.body.scrollTop);
    			//alert(document.documentElement.scrollTop);
    			//suspendNavigation.style.top=document.body.scrollTop+"px";
    			suspendNavigation.style.top=(document.documentElement.scrollTop||document.body.scrollTop)+"px";
    			
    		}
    	}
    </script>
    </html>
    

      

  • 相关阅读:
    CheckBox循环删除代码
    最小二乘法原理
    break_VS_continue
    check the sentence &ff
    check_return
    check_FunctionAddress
    while执行两次的问题,已经解决
    CalculationWithDifferenceTpye
    SaveAboutZero
    check_negation
  • 原文地址:https://www.cnblogs.com/hephec/p/5487017.html
Copyright © 2011-2022 走看看