jQuery相当于MooTools的Scroll()。toElementCenter()

时间:2016-06-15 10:42:07

标签: jquery mootools

我正在调整别人的脚本到我的网站。使用MooTools;我使用jQuery。他们的代码有以下几行:

new FX.Scroll(window).toElementCenter('obj');

我如何在jQuery中执行此操作?

1 个答案:

答案 0 :(得分:1)

如果您check the docs,您会看到此行

new FX.Scroll(window).toElementCenter('obj');

基本上是指:

  

使用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