动态加载 div 时使 iscroll 起作用
任何人都可以解释一下,如果可能的话,举个例子,如何在 iscroll div 中加载动态内容并为其分配新的高度?
我可以让它工作,但我无法控制新内容的滚动高度。
我对这一切都很陌生,不知道如何开始。
这是我正在做的事情:
http://homepage.mac.com/jjco/test/index7.html< /a>
当页面加载时,您会看到滚动条,其中没有内容... 单击 print/damm (显示我最初为此内容设置的高度) 单击 print/fcbarcelona (保持与之前使用的滚动条相同的高度和位置),您会发现它无法正常工作。 显然,我不希望卷轴在不必要的时候出现在那里。
任何帮助将不胜感激。
can anyone please explain, with an example if possible, how to load dynamic content inside an iscroll div and assign a new height to it?
I can get it to work but I can't control the height of the scroll for the new content.
I'm new to all this and have no clue were to start.
here's what I'm working on:
http://homepage.mac.com/jjco/test/index7.html
when the page is loaded you see the scroll bar where there's no content...
clicking on print/damm (shows the height I originally set for this content)
clicking on print/fcbarcelona (maintains the same height and position of the scroll you used before) as you see it's not working as it should.
obviously, I don't want the scroll to be there when it's not necessary.
any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
最好使用iScroll中的refresh()方法,它会重新计算高度。
It's better to use the refresh() method in iScroll, which will recalculate the height.
我遇到了类似的问题,只是
refresh()
没有帮助,因此对销毁和重新创建 iScroll 没有帮助。就我而言,我将很多元素加载到 iScroll div 中。解决这个问题的是setTimeout()
。正如 掌握 REFRESH() 方法 所说,甚至将0ms
添加到setTimeout() 可以解决很多问题。就我而言,它是
500ms
。 =这里是代码示例:
我的问题是
refresh()
函数在内容插入 DOM 之前执行,因此增加超时会有所帮助。我希望它对像我这样的初学者有帮助。I had a similar problem, and just
refresh()
didn't help, so didn't help destroying and recreating iScroll. In my case I was loading a lot of elements into iScroll div. What did solve the problem issetTimeout()
. As MASTERING THE REFRESH() METHOD said adding even0ms
to asetTimeout()
would solve a lot of problems. In my case it was500ms
. =here is code sample:
My problem was that
refresh()
function was executed before content was inserted into DOM, so increasing timeout helped. I hope it helps to beginners like me.尝试一下,当您将新数据插入 iScroll 时,请执行以下步骤
try this, when you insert your new data into iScroll do these steps
要观察高度变化:
To watch height changes:
看看 iScroll4
在 iscroll.js 中,我看到实验性选项: checkDOMChanges: false,// Experimental
您可以启用并使用它。
Take a look at iScroll4
In iscroll.js, I see experimental option: checkDOMChanges: false,// Experimental
You can enable and use it.