[英]scroll to animate selected anchor in jquery
I have simple JS function that's animate page scroll to selected anchor by id 我有简单的JS函数,可通过id动画页面滚动到选定的锚点
all anchor in my page have different offset value and position tip: I user masonry effect but does not work correctly 页面中的所有锚点都有不同的偏移值和位置提示:我使用石工效果,但无法正常工作
function scrollToAnchor(aid) {
var aTag = $("a[id='" + aid + "']");
$('html,body').animate({ scrollTop: aTag.position().top }, 'slow');
}
You should use offset instead of position(). 您应该使用offset而不是position()。
But I know by experience that Masonry by default doesn't use position absolute & top, left but it uses a css3-transform instead. 但是我从经验中知道,默认情况下Masonry不使用绝对位置和顶部位置,而是使用css3-transform。 And this means that .left and .top will output 0 instead of the css3-transform-value.
这意味着.left和.top将输出0而不是css3-transform-value。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.