jQuery 相当于 MooTools 的 Scroll().toElementCenter()
jQuery equivalent of MooTools' Scroll().toElementCenter()
我正在将其他人的脚本改编为我的网站。使用MooTools;我使用 jQuery。他们的代码有下面一行:
new FX.Scroll(window).toElementCenter('obj');
我如何在 jQuery 中执行此操作?
如果你check the docs看到这一行
new FX.Scroll(window).toElementCenter('obj');
基本上是指:
Do a animated scroll to the center of the element with the id "obj
"
在 jQuery 中,可以用
完成
var obj = $('#obj'); // cache the element
$('html, body').animate({
scrollTop: obj.offset() + (obj.height() / 2) // scroll to top of element + half of its height
}, 1000); // 1 second fast animation
我正在将其他人的脚本改编为我的网站。使用MooTools;我使用 jQuery。他们的代码有下面一行:
new FX.Scroll(window).toElementCenter('obj');
我如何在 jQuery 中执行此操作?
如果你check the docs看到这一行
new FX.Scroll(window).toElementCenter('obj');
基本上是指:
Do a animated scroll to the center of the element with the id "
obj
"
在 jQuery 中,可以用
完成var obj = $('#obj'); // cache the element
$('html, body').animate({
scrollTop: obj.offset() + (obj.height() / 2) // scroll to top of element + half of its height
}, 1000); // 1 second fast animation