Javascript fixed page top floating navigation menu effect

Source: Internet
Author: User
Tip: you can modify some code before running

<!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><title>Practical fixed floating effect on top of webpage</title><meta http-equiv="content-type" content="text/html;charset=gb2312"><!--把下面代码加到<head>与</head>之间--><style type="text/css">* {Margin: 0; padding: 0;} ul, li {list-style: none;} # content {width: 600px; margin: 0 auto; border: 1px solid # f00;} ul li. zzjs {width: 400px; text-align: center; margin: 20px 100px; background: # 00f; color: # fff; font-size: 14px; font-weight: bold; height: 100px; line-height: 100px; }# fudong {position: absolute; top: 0; left: 50%; width: 900px; margin-left:-pixel px; height: 30px; line-height: 30px; text-align: center; background: #000; color: # fff; font-size: 14px; font-weight: bold; z-index: 2 ;}</style></head><body><div ></div><!--把下面代码加到<body>与</body>之间--><div id="fudong">Web page creation tutorial http://www.111cn.net</div><script language="javascript">Var speed = 100; var scrollTop = null; var hold = 0; var fudong; var pos = null; var timer = null; var moveHeight = null; fudong = document. getElementById ("fudong"); window. onscroll = scroll_ad; function scroll_ad () {scrollTop = document.doc umentElement. scrollTop + document. body. scrollTop; pos = scrollTop-fudong. offsetTop; pos = pos/10 moveHeight = pos> 0? Math. ceil (pos): Math. floor (pos); if (moveHeight! = 0) {fudong. style. top = fudong. offsetTop + moveHeight + "px"; setTimeout (scroll_ad, speed);} // alert (scrollTop );}</script></body></html></td> </tr></table>
Tip: you can modify some code before running

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.