javascript - 关于iscroll.js滚动容器中动态插入的元素无法滚动的问题,该如何解决?

WBOY
Release: 2016-07-06 13:53:27
Original
1501 people have browsed it

直接写在html里面的内容能滚动,用js动态插入的html结构则无法滚动,是怎么回事?

回复内容:

直接写在html里面的内容能滚动,用js动态插入的html结构则无法滚动,是怎么回事?

iScroll对象有个方法叫做refresh(),插入html后调用该方法即可

你好楼主,我之前也遇到过这个问题,你只需要先将html结构用js插入页面后再实例化iscroll就可以了,希望可以帮到你!

<code>like this

   $('#cart-pop').html(str);
   stateMap.myScroll3 = new IScroll('#wrapper-cart', { mouseWheel: true, click: true,probeType: 2});</code>
Copy after login

这种情况是因为,初始化iscroll时,scroller高度并不是固定的。你可以在加载完你的dom后初始化iscroll。比如把iscroll的初始化方法写在ajax的success函数里面。

让iscroll重新计算一下高度就好了

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!