jquery根据锚点offset值实现动画切换
2014-09-11 17:05
706 查看
锚点相信大家都使用过吧!点击后僵硬的切换是不是很不爽呢?
下面分享一个小技巧,根据锚点offset值来实现动画切换
<!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 type="text/javascript" src="js/jquery-1.8.3.min.js"></script> <style> *{ margin:0; padding:0;} .main{ width:1000px; margin:0 auto; position:relative; } .main img{ float:left;} .bg{ position:absolute; width:100%; z-index:-5;} .bg01{ height:885px;background:url(../images/b_01.jpg) no-repeat center;} .bg02{ height:938px;background:url(../images/b_04.jpg) no-repeat center; } .bg03{ height:946px;background:url(../images/b_02.jpg) no-repeat center; } .bg04{ height:946px;background:url(../images/b_03.jpg) no-repeat center; } .div_scoll{ position:fixed; width:50px; height:200px; right:100px; top:50%;} a{ display:block; background:#3F6; color:#000; width:50px; height:50px; } </style> </head> <body> <div class="wrapper"> <div class="main"> <div id="tab_01" class="tab"><img src="images/m_01.jpg" alt="" /></div> <div id="tab_02" class="tab"><img src="images/m_04.jpg" alt="" /></div> <div id="tab_03" class="tab"><img src="images/m_02.jpg" alt="" /></div> <div id="tab_04" class="tab"><img src="images/m_03.jpg" alt="" /></div> </div> <div class="bg"> <div class="bg01" id="bg01"></div> <div class="bg02" id="bg02"></div> <div class="bg03" id="bg03"></div> <div class="bg04" id="bg04"></div> </div> </div> <div class="div_scoll"> <a href="#bg01">图1</a> <a href="#bg02">图2</a> <a href="#bg03">图3</a> <a href="#bg04">图4</a> </div> <script> $(function(){ $(".div_scoll a").click(function(){ $("html,body").animate({ scrollTop:$($(this).attr("href")).offset().top + "px"},1000); }); }); </script> </body> </html>
您可能感兴趣的文章:
相关文章推荐
- jquery根据锚点offset值实现动画切换
- jquery根据锚点offset值实现动画切换
- 用jQuery和css3实现的一个模仿淘宝ued博客左边的菜单切换动画效果
- jQuery插件Slider Revolution实现响应动画滑动图片切换效果
- jQuery插件slicebox实现3D动画图片轮播切换特效
- 【jQuery】调用toggle()方法实现动画切换效果
- jquery实现tab选项卡切换效果(悬停、下方横线动画位移)
- jQuery的animate函数实现图文切换动画效果
- jquery实现初次打开有动画效果的网页TAB切换代码
- jQuery插件Slider Revolution实现响应动画滑动图片切换效果
- jQuery实现分章节锚点“回到顶部”动画特效代码
- jQuery实现分章节锚点“回到顶部”动画特效代码
- jQuery实现图片与文本信息切换动画效果
- jquery实现隐藏与显示动画效果/输入框字符动态递减/导航按钮切换
- 利用Jquery队列实现根据输入数量显示的动画
- 使用jQuery和css3实现了仿淘宝ued博客左边的菜单切换动画
- jquery实现初次打开有动画效果的网页TAB切换代码
- jQuery的animate函数实现图文切换动画效果
- JQuery移动动画实现点击按钮切换图片--JQuery基础