2012-05-13 58 views
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 !!!

同時,如果我用純代碼替換加載函數,它將正確滾動。

我錯過了什麼嗎?

回答

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); 
}); 
+0

我嘗試過使用您的代碼,但它不工作。將事件綁定到#htmltext也不起作用。 我已經使用了CSS函數,比如'code'transform(),transform3d(),...但它們裁剪內容,不滾動內容。 – TonyWu

+0

@TonyWu代碼可行。檢查你的'scrollview'函數。它存在嗎?我知道'.scrollTop()'方法,不能說這個。 – VisioN

+0

它理論上看起來很有作用,但實際上它不起作用。 加載後沒有事件觸發事件: 'Link //加載故事內容。 $('#htmltext')。load(「test.htm」,function(response,status,xhr){if(status ==「error」){ var msg =「對不起,但出現錯誤:」 ; console.error(msg + xhr.status +「」+ xhr.statusText); } $('#ctrl')。trigger('click'); }); ('#ctrl')。bind('click',function(event){ console.log(「ctrl.click」); $('#htmltext')。scrollview(「scrollTo」,0, -600); });' scrollview()屬於jquery.mobile.scrollview.js – TonyWu