1

标题:

<script src="jquery.mobile/jquery.easing.1.3"></script>
<script src="jquery.mobile/jquery.mobile.scrollview"></script>
<script src="jquery.mobile/scrollview"></script>
....! and the correct css !

身体:

<div data-role="page" data-theme="a" id="mainpage">
    <div data-role="content" data-theme="a">
        <div id="htmltext" data-scroll="y"></div>
    </div><!-- /content -->
</div>

在 Pageshow 事件中:

$("#htmltext").load("content/test.htm", function(response, status, xhr) {
    if (status == "error") {
        var msg = "Sorry but there was an error: ";
        alert(msg + xhr.status + " " + xhr.statusText);
    }
});

$("#htmltext").scrollview("scrollTo", 0, -600);

load() 后,无法滚动动态 div #htmltext!!!

同时,如果我用纯代码替换加载函数,它将正确滚动。

我错过了什么吗?

4

1 回答 1

0

问题可能来自 Ajax 异步工作的事实。所以为了在 Ajax 加载做任何事情,你应该使用它的回调函数。尝试在load处理函数中移动滚动方法。

$("#htmltext").load("content/test.htm", function(response, status, xhr) {
    if (status == "error") {
        var msg = "Sorry but there was an error: ";
        alert(msg + xhr.status + " " + xhr.statusText);
    }
    $("#htmltext").scrollview("scrollTo", 0, -600);
});
于 2012-05-13T01:52:59.053 回答