jQuery – 捲軸滾動到指定的錨點
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(document).ready(function() { $("a").click(function() { console.log($(this).attr("href")) var $body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body'); $body.animate({ scrollTop: $($(this).attr("href")).offset().top + "px" }, { duration: 500, easing: "swing" }); return false; }); }); </script> <div> <a href="#footer">HELLOW</a> <div id="footer" style="margin-top:10000px;"> FOOTER </div> </div> |