jquery根據錨點offset值實現動畫切換,jqueryoffset

來源:互聯網
上載者:User

jquery根據錨點offset值實現動畫切換,jqueryoffset

錨點相信大家都使用過吧!點擊後僵硬的切換是不是很不爽呢?

下面分享一個小技巧,根據錨點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 實現的頁內類錨點的平滑跳轉

$("#div").animate({scrollTop:$("#div").offset().top}, 500);
 
我做了一個相當於錨點切換的頁面,在使用jquery時寫切換綁定遇到問題,具體代碼如

同學.... 你的代碼語法錯誤一堆, 邏輯錯誤一堆, 實在不知道從何說起了
你詳細描述一下你的需求是什麼吧
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.