jQuery的平滑页面内锚定链接插件:$.smoothAnchor()

日期:2011/11/23  来源:GBin1.com

jQuery的平滑页面内锚定插件提供给你一个轻量级的脚本帮助你添加页面内的锚定帮助你平滑的滚动页面。当然这里有其它的类似插件,不过这个是比较轻量级的版本。只有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">

希望大家喜欢!

来源: jQuery的平滑页面内锚定链接插件:$.smoothAnchor()

原文地址:https://www.cnblogs.com/gbin1/p/2261989.html