举例来说,在基于引导程序的应用程序中,我可能会编写标记,使网格对于大屏幕为8列宽,对于小屏幕为2列宽.
屏幕尺寸肯定会对屏幕设计产生影响,我想知道在我开始在famo.us中尝试之前要遵循什么样的模式.看到famo.us是"意见",这里应该只有一个答案:)
我全都是移动优先设计,但我不想要的是桌面应用程序,它只是一个延伸400%的移动应用程序.
谢谢,
安德鲁
基于Github上的Famo.us示例中的示例..
https://github.com/Famous/examples/blob/master/src/examples/views/GridLayout/example.js
你可以很容易地做这样的事情..
var Engine = require("famous/core/Engine");
var Surface = require("famous/core/Surface");
var GridLayout = require("famous/views/GridLayout");
var mainContext = Engine.createContext();
var contextSize = mainContext.getSize()
var dimensions;
if (contextSize[0] < 480 || contextSize[1] < 480) {
dimensions = [2,8];
} else {
dimensions = [8,2];
};
var grid = new GridLayout({
dimensions: dimensions
});
var surfaces = [];
grid.sequenceFrom(surfaces);
for(var i = 0; i < 16; i++) {
surfaces.push(new Surface({
content: "I am panel " + (i + 1),
size: [undefined, contextSize[1] / 2.0],
properties: {
backgroundColor: "hsl(" + (i * 360 / 16) + ", 100%, 50%)",
color: "black",
lineHeight: window.innerHeight / 2 + 'px',
textAlign: 'center'
}
}));
}
mainContext.add(grid);
Run Code Online (Sandbox Code Playgroud)
编辑:
因为最终目标是Javascript作为现代Web应用程序的唯一开发语言.有时您只需要自己管理事物.
对于像Famo.us这样强烈依赖于绝对定位的框架尤其如此.事情就像箱子模型一样不流畅
为了处理所有细微差别,我构建了一个StateHash类来管理状态,并根据当前状态返回相同键的不同值.
var DESKTOP, MOBILE, StateHash, screen_state, sh;
StateHash = (function() {
function StateHash(states) {
this.set_state = __bind(this.set_state, this);
this.get_state = __bind(this.get_state, this);
this.set = __bind(this.set, this);
this.get = __bind(this.get, this);
var i, _i, _ref;
if (!states) {
states = 2;
}
this.state = 0;
this.hash = {};
for (i = _i = 0, _ref = states - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
this.hash[i] = {};
}
}
StateHash.prototype.get = function(key) {
return this.hash[this.state][key];
};
StateHash.prototype.set = function(state, key, val) {
return this.hash[state][key] = val;
};
StateHash.prototype.get_state = function() {
return this.state;
};
StateHash.prototype.set_state = function(state) {
return this.state = state;
};
return StateHash;
})();
// Usage
MOBILE = 0;
DESKTOP = 1;
screen_state = some_check_mobile_function() ? MOBILE : DESKTOP;
sh = new StateHash();
sh.set_state(screen_state);
sh.set(MOBILE, "top-margin", "10px");
sh.set(DESKTOP, "top-margin", "20px");
sh.get("top-margin");
Run Code Online (Sandbox Code Playgroud)
如果我了解其他任何更好的方法,我会告诉你的!
祝好运!