18个非常棒的jQuery代码片段

18个非常棒的jQuery代码片段

1、jQuery实现的内链接平滑滚动

不需要使用太复杂的插件,只要使用下载这段代码即可实现基于内部链接的平滑滚动

$(a[href^=”#”]).bind(click.smoothscroll,function (e) {
e.preventDefault();

var anchor = this.hash,
$target = $(target);

$(html, body).stop().animate({
scrollTop: $target.offset().top
}, 500, swing, function () {
window.location.hash = anchor;
});

});

2、使用jQuery获取所有节点

var $element = $(#gbtags);
var $nodes = $element.contents();
$nodes.each(function() {
if(this.nodeType === 3

© 版权声明

相关文章

暂无评论

none
暂无评论...