网页的单页面滚动做法
2013-04-10 20:31
183 查看
主要用到锚点知识点
<!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> <script src="http://code.jquery.com/jquery-1.5.js"></script> <style type="text/css"> *{ margin:0; padding:0;} .wrapper{ width:900px; margin: 0 auto; background:#FFBFAA;} .hd{ height:30px; text-align:right;position:fixed;z-index:9999;background:#000;width:900px;float:right;top:0;} .hd li{ float:left; list-style:none;} .hd li a{ display:block; height:30px;line-height: 30px;text-align:center; margin-right:10px; background:#FF9FAA; font:16px "微软雅黑"; color:#fff; font-weight:700px;width:100px;} hd li a.no_con{display:none;} .hd li a.active{background:#000;} .home{ height:350px; background:#D4DF00;} .about{ background:#FF3F55;} .link{ background:#f1f1f1;} .mian_body{padding-top:30px;} .mian_body,.hd ul{ position:relative;} </style> </head> <body> <div class="wrapper"> <div class="hd"> <ul> <li><a rel="scroll" href="#home" class="active">home</a></li> <li><a rel="scroll" href="#about">about</a></li> <li><a rel="scroll" href="#contact">contact</a></li> </ul> </div> <div class="mian_body"> <div id="home" class="home">home内容</div> <div id="about" class="home about">about内容</div> <div id="contact" class="home link">contact内容</div> <div class="home">底部内容</div> </div> </div> <script> var anchor_scroll_speed =350; $.scroll_to = function(element, speed, offset) { if (!offset) { var offset = 0; } $("html, body").animate({ scrollTop: element.offset().top + offset }, speed); }; $(function(){ $("a[rel~='scroll']").click(function(e) { var self = $(this); e.preventDefault(); var anchor = self.attr("href"); $.scroll_to($(anchor), anchor_scroll_speed,-30); }); $(".hd a").click(function(e) { var self = $(this); e.preventDefault(); $(".hd a").removeClass("active"); self.addClass("active"); }); }) </script> </body> </html>
相关文章推荐
- IOS设备上网页中的页面滚动效果模拟
- APP开发网页自动滚屏动态加载 页面滚动动态加载数据,页面下拉自动加载内容
- IOS设备上网页中的页面滚动效果模拟
- [js]网页侧边随页面滚动广告效果实现
- 如何抓取Js动态生成数据且以滚动页面方式分页的网页
- web网页input框设置,点击input框弹出键盘,再收回键盘,焦点框会随页面滚动
- 关于网页页面制作滚动字幕
- 制作一个简易的网页,用不同的颜色区分头部、内容以及底部,在滚动页面的过程中,底部保持不变。
- 抓取Js动态生成数据且以滚动页面方式分页的网页
- 利用Selenium模拟页面滚动,结合PicCrawler抓取网页上的图片
- jquery实现网页的页面平滑滚动效果代码
- 移动端页面 弹出框滚动,底部body锁定,不滚动 / 微信网页禁止回弹效果
- 网页上右边有一个微信二维码随着页面滚动而不动的效果
- 如何抓取Js动态生成数据且以滚动页面方式分页的网页
- 实现双击网页后页面自动向上滚动
- 抓取Js动态生成数据且以滚动页面方式分页的网页
- 『网页制作』页面滚动HTML代码
- 网页中adobe PDF显示,js控制pdf页面滚动
- 如何抓取Js动态生成数据且以滚动页面方式分页的网页
- js网页侧边随页面滚动广告效果实现