动态加载 div 时使 iscroll 起作用

发布于 2024-12-10 01:11:30 字数 429 浏览 1 评论 0原文

任何人都可以解释一下,如果可能的话,举个例子,如何在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

唐婉 2024-12-17 01:11:30

最好使用iScroll中的refresh()方法,它会重新计算高度。

myScroll.refresh();

It's better to use the refresh() method in iScroll, which will recalculate the height.

myScroll.refresh();
不醒的梦 2024-12-17 01:11:30

我遇到了类似的问题,只是 refresh() 没有帮助,因此对销毁和重新创建 iScroll 没有帮助。就我而言,我将很多元素加载到 iScroll div 中。解决这个问题的是setTimeout()。正如 掌握 REFRESH() 方法 所说,甚至将 0ms 添加到 setTimeout() 可以解决很多问题。就我而言,它是500ms。 =

这里是代码示例:

    var myScroll;

    function createIScroll(){
    myScroll = new iScroll('wrapper');
    }

    function iScrollRefresh(){
      setTimeout(function(){
         myScroll.refresh(); 
      }, 500);
    }
$ajax(){ 
//receiving data
}
function someFunction(){
  //dynamic content is created
  iScrollRefresh();
}

我的问题是 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 is setTimeout(). As MASTERING THE REFRESH() METHOD said adding even 0ms to a setTimeout() would solve a lot of problems. In my case it was 500ms. =

here is code sample:

    var myScroll;

    function createIScroll(){
    myScroll = new iScroll('wrapper');
    }

    function iScrollRefresh(){
      setTimeout(function(){
         myScroll.refresh(); 
      }, 500);
    }
$ajax(){ 
//receiving data
}
function someFunction(){
  //dynamic content is created
  iScrollRefresh();
}

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.

痴骨ら 2024-12-17 01:11:30

尝试一下,当您将新数据插入 iScroll 时,请执行以下步骤

//myScroll is a global variable you initialize iScroll on
myScroll.destroy();
myScroll = null;
loaded();//this is a functions where you have have your iScroll initializer 

try this, when you insert your new data into iScroll do these steps

//myScroll is a global variable you initialize iScroll on
myScroll.destroy();
myScroll = null;
loaded();//this is a functions where you have have your iScroll initializer 
帅的被狗咬 2024-12-17 01:11:30

要观察高度变化:

setInterval(function () {
    var newScrollerHeight = $scroller.innerHeight();

    if (newScrollerHeight !== prevScrollerHeight) {
         prevScrollerHeight = newScrollerHeight;
         myScroll.refresh();
    }
}, 500);

To watch height changes:

setInterval(function () {
    var newScrollerHeight = $scroller.innerHeight();

    if (newScrollerHeight !== prevScrollerHeight) {
         prevScrollerHeight = newScrollerHeight;
         myScroll.refresh();
    }
}, 500);
流心雨 2024-12-17 01:11:30

看看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文