2011-03-31 66 views
3

我剛開始爲iPad開發一些類似web應用程序的網站。我使用YUI的scrollView列表,這很好地工作。Yahoo yui和iPad方向

現在的問題是,當方向發生變化時,我必須更新滾動條實例的高度,但我不知道如何完成。

據我所知,應該有一些聽衆和事件參數或我的雜亂的代碼片段。有任何想法嗎?

YUI().use("scrollview", function (Y) { 


    if(window.orientation == 0) // Temp solution to set the right height on load. 
     { var iheight = 740; } 
    else if(window.orientation == 90 || window.orientation == -90) 
     { var iheight = 480; } 

    var scrollview = new Y.ScrollView({ 
     id: "scrollview", 
     srcNode: '#scrollable', 
     height: iheight,   
     flick: { 
      minDistance:10, 
      minVelocity:0.3, 
      axis: "y"} 
    }); 

    scrollview.render(); 

    scrollView._uiDimensionsChange(); // Think I'm supposed to use this somehow. 
}); 
+0

你讀過[this thread](http://yuilibrary.com/forum/viewtopic.ph P + P = 22599)? – 2011-03-31 13:47:40

+0

是的,但是當我看到它時,他們正在談論全屏佈局和身體課程。礦井更像是一個具有特定寬度/高度的裝箱清單,取決於設備的方向。 – Xavio 2011-03-31 14:13:27

回答

1

要改變高度,所有你需要做的是這樣的:

scrollView.setAttrs({height: 500}); 

執行該代碼時的方向變化,這應該工作(雖然我不能測試它,因爲我不是在移動瀏覽器):

YUI().use("scrollview", function (Y) { 

    function getHeight() { 
     switch (window.orientation) { 
      case 0: 
       return 740; 
      case 90: 
      case -90: 
       return 480; 
      default: 
       return ???; 
     } 
    } 

    var scrollview = new Y.ScrollView({ 
     id: "scrollview", 
     srcNode: '#scrollable', 
     height: getHeight(),   
     flick: { 
      minDistance:10, 
      minVelocity:0.3, 
      axis: "y"} 
    }); 

    scrollview.render(); 

    Y.on("orientationchange", function (e) { 
    { 
     scrollView.setAttrs({ 
      height: getHeight() 
     }); 
    }); 
}); 
+0

但是我如何在代碼中使用它? – Xavio 2011-03-31 14:31:28

+0

您在執行方向更改時執行的回調中執行該操作。讓我看看我能否找到如何設置它。 – 2011-03-31 14:41:49

+0

@Xavio:看我的編輯。 – 2011-03-31 14:47:29