jQuery的平滑頁面內(nèi)錨定鏈接插件:$.smoothAnchor()
日期:2011/11/23 來源:GBin1.com
jQuery的平滑頁面內(nèi)錨定插件提供給你一個輕量級的腳本幫助你添加頁面內(nèi)的錨定幫助你平滑的滾動頁面。當然這里有其它的類似插件,不過這個是比較輕量級的版本。只有2kb,希望大家喜歡!
jQuery代碼
var JQUERY4U = {}
JQUERY4U.UTIL = {
/*
* Utility function used to make anchor links animate smoothly instead of jumping.
*/
smoothAnchor: function (anchorClass)
{
$('a.'+anchorClass).click(function () {
elementClick = $(this).attr("href")
destination = $(elementClick).offset().top;
$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
return false;
})
}
}
<script type="text/javascript">
$(document).ready(function() {
JQUERY4U.UTIL.smoothAnchor('anchorLink');
});
</script>
使用方式
錨定鏈接
<!-- anchor link -->
<a href="#pagelink-1" class="anchorLink"><em>how much can I borrow?</em></a>
目標元素
<!-- target element -->
<div id="pagelink-1">
希望大家喜歡!
歡迎訪問GBin1.com


浙公網(wǎng)安備 33010602011771號