jQuery – 捲軸滾動到指定的錨點
2013-05-29 / JSN / 0 Comments / 2,581 次瀏覽
<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>
相關文章
#animate#jQuery#scrollTop#捲軸#滾動#錨點