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をスクロールできません!!!

一方、load関数を純粋なコードに置き換えると、正しくスクロールされます。

私は何かを逃しましたか?

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 に答える