我刚刚开始为iPad开发一些类似Web应用程序的网站。我正在使用YUI的scrollView列表,这很好用。
现在的问题是,当方向改变时,我必须更新scroller-instance的高度,我不知道如何完成。
据我所知,在我凌乱的代码中应该有一些听众和事件参数。有什么想法吗?
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 :(得分: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()
});
});
});