标题
<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 !!!
同时,如果我用纯代码替换加载函数,它将正确滚动。
我错过了什么吗?
答案 0 :(得分: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);
});