简体   繁体   English

左侧水平滚动无法正常工作

[英]Horizontal scroll left doesn't work properly

I would like when i click on button , the div scroll to specified area. 我希望当我点击按钮时, div滚动到指定区域。 for first click all things is ok.but for second click and more , the scroll animataion doesn't work or work with much delays ! 首次点击所有的东西都是好的。但是对于第二次点击等等,滚动动画不起作用或工作有很多延迟! This is my jsfiddle : http://jsfiddle.net/AliN11/7CgFp/3/ 这是我的jsfiddle: http//jsfiddle.net/AliN11/7CgFp/3/

note: when opening jsfidde please scroll little horizontal scroll in result section of my jsfiddle. 注意:打开jsfidde时,请在我的jsfiddle的结果部分滚动一点水平滚动。

You're appending a new click handler every time the window scrolls. 每次窗口滚动时,您都会附加一个新的单击处理程序。 This is not what you want. 这不是你想要的。 Just append the click handlers once and be done with it. 只需附加点击处理程序一次即可完成。

$("#b1").click(function(){$("#main").animate({ scrollLeft:110 }, "fast");});
$("#b2").click(function(){$("#main").animate({ scrollLeft:210 }, "fast");});
$("#b3").click(function(){$("#main").animate({ scrollLeft:310 }, "fast");});
$("#b4").click(function(){$("#main").animate({ scrollLeft:410 }, "fast");});

http://jsfiddle.net/7CgFp/4/ http://jsfiddle.net/7CgFp/4/

Change your javascript like this: 像这样更改你的javascript:

 $(document).ready(function(){
        $("#b1").click(function(){$("#main").animate({ scrollLeft:110 }, "fast");});
        $("#b2").click(function(){$("#main").animate({ scrollLeft:210 }, "fast");});
        $("#b3").click(function(){$("#main").animate({ scrollLeft:310 }, "fast");});
        $("#b4").click(function(){$("#main").animate({ scrollLeft:410 }, "fast");});

    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM