简体   繁体   English

jQuery的移动bug与scrollTop

[英]JQuery mobile bug with scrollTop

In the following link I have attached a sample of my source code: 在以下链接中,我附加了我的源代码示例:

http://jsfiddle.net/xY7tx/2381/ http://jsfiddle.net/xY7tx/2381/

I have a list of 34 items when you press down the keyboard and you reach the 10th item, it would successfully scrollTop to 11th element. 当您按下键盘并到达第10个项目时,我有34个项目的列表,它将成功scrollTop到第11个元素。 But when you keep pressing down and when you reach 20th item, with my code it supposed to scrollTop to 21th item but it isn't. 但是,当您持续按下并到达第20个项目时,按照我的代码,它应该scrollTop到第21个项目,但事实并非如此。

To reproduce the bug please keep pressing down on keyboard and pay attention to the 20th ---> 21th item which is not desirable (and compare it with 10th --> 11th item change which is desirable). 要重现该错误,请继续按下键盘,并注意不希望出现的第20个->第21个项目(并将其与希望发生的第10个->第11个更改进行比较)。

If i have done any mistake, my apologies and please show me in the source code what change should I make so that in change of 20th to 21th item, it would scrollTop as well. 如果我犯了任何错误,我深表歉意,并请在源代码中告诉我应该进行哪些更改,以便在第20项到第21项的更改中,它也将scrollTop Thanks! 谢谢!

Edit: Thanks to ezanker. 编辑:感谢ezanker。 with his answer , i can now scrollTop to the item of 21th , but still there is a problem when i want to scrollTop t the 31th item , still it isn't working with the current code . 有了他的回答,我现在可以将scrollTop移到第21个条目,但是当我想在第31个条目上滚动时仍然存在问题,仍然无法使用当前的代码。 please keep pressing down on keyboard until 31th item , you would see the problem. 请持续按住键盘直到第31项,您将看到问题。

The problem is that you are setting 问题是您正在设置

var container = $('div'),

but jQuery Mobile automatically creates a page div to wrap around your code if you do not explicitely provide the div. 但如果您未明确提供div,jQuery Mobile会自动创建一个页面div来包装您的代码。 Change it to 更改为

var container = $('#listAddr'),

Updated FIDDLE 更新了FIDDLE

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

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