我正在使用脚本从这里顺利滚动Smooth scrolling when clicking an anchor link(URL被更改的版本)。平滑滚动不适用于a。在ID
它适用于除ID为.
之外的所有锚点。因此,链接到:
1的工作
1.1不起作用
如何解决这个问题的任何想法?
代码:
var $root = $('html, body');
$('a').click(function() {
var href = $.attr(this, 'href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function() {
window.location.hash = href;
});
return false;
});
演示:http://bagsy.netau.net/rj/rj.html
的[这]可能的复制(http://stackoverflow.com/questions/350292/how-do-i-get- jquery-to-select-elements-with-a-period-in-their-id) – trincot