如何使用动画属性在单击时将水平(左/右)滚动到特定div [英] How to scroll horizontaly(left/right) to a particular div on click using animation prperty
本文介绍了如何使用动画属性在单击时将水平(左/右)滚动到特定div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试做的是让它如果你点击一个按钮,它会水平(平滑地)滚动到页面上的特定div。怎么做?
我尝试了什么:
我尝试过offset.left但它无法正常工作
What Im trying to do is make it so that if you clicking on a button, it scrolls horizontzly(smoothly) to a specific div on the page. How to do that?
What I have tried:
I have tried offset.left but it doesnt works properly
推荐答案
这样的事情应该有效:
Something like this should work:
var left =
( #idOfTheTargetHere)。offset()。left;
("#idOfTheTargetHere").offset().left;
( html,body)。animate({scrollLeft:left}, 500 );
("html, body").animate({ scrollLeft: left }, 500);
将 #idOfTheTargetHere
更改为jQuery选择器,该选择器选择要滚动到视图中的元素。
Change #idOfTheTargetHere
to the jQuery selector which selects the element you want to scroll into view.
这篇关于如何使用动画属性在单击时将水平(左/右)滚动到特定div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文