我正在调整别人的脚本到我的网站。使用MooTools;我使用jQuery。他们的代码有以下几行:
new FX.Scroll(window).toElementCenter('obj');
我如何在jQuery中执行此操作?
答案 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