当我使用Ajax渲染Scroller部件时,iScroll不起作用 [英] When I am using ajax to render the Scroller part iScroll doesn't work
问题描述
我遇到了一个奇怪的问题.
I met a strange problem.
如果我使用"for循环"将html呈现到滚动部分中,则一切正常.
If I use "for loop" to render html into scroller part,everything works well.
但是当我使用ajax将数据呈现到滚动器部件中时,iScroll不起作用(无法滚动).
But when I am using ajax to render my data into scroller part.iScroll doesn't work(can't scroll).
这是我的网址: http://yuanwang.sinaapp.com/8505/item.html
您可以复制我的代码并尝试一下.
You can copy my code and try yourself.
打开item.js并尝试运行"for循环",您会看到一切运行正常.
Open the item.js and try to run "for loop",you can see everything runs well.
推荐答案
您是否尝试过在.ajax()
调用的成功函数中设置iScroll?看起来您正在尝试在各种定时事件之后进行各种调用loaded
的迭代,但是我认为,一旦将所有DOM元素添加到您的 .success()
函数.
Have you tried setting up your iScroll inside the success function of your .ajax()
call? It looks like you're trying various iterations of calling loaded
after various timed events but I think you'll find more success if you set it up once all the DOM elements have been added inside your .success()
function.
也许是这样的:
for ...
for ...
$('#thelist').append("<li>"+ co...
}
}
myScroll = new iScroll('wrapper');
更新:
或者在添加所有内容后直接调用loaded()
函数.
Or just call your loaded()
function once everything has been added.
全面披露:我从未使用过iScroll,因此您的实现中可能存在一个我不会注意到的错误.创建iScroll
的新实例后,可能必须对myScroll
做一些事情.我不确定.
Full disclosure: I haven't used iScroll ever so there may be a mistake in your implementation that I wouldn't notice. You may have to do something with your myScroll
after you have created a new instance of iScroll
. I'm not sure.
让我知道这是否不能解决您的情况.
Let me know if this doesn't address your situation.
这篇关于当我使用Ajax渲染Scroller部件时,iScroll不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!