我希望边距是一个新变量,但每次调整窗口大小时,它都会改变值
检查控制台并尝试调整大小:
http://robintimman.com/test/ab/
JS:
var s,
appWidget = {
settings: {
btnClass: ".object",
main: {},
btns: {},
icon: {},
current: {},
next: {},
prev: {}
},
init: function(){
s = this.settings;
m = this.settings.main;
b = this.settings.btns;
i = this.settings.icon;
c = this.settings.current;
n = this.settings.next;
p = this.settings.prev;
appWidget.bindUIActions();
$(window).bind("resize", appWidget.resizeWindow);
appWidget.resizeWindow();
},
resizeWindow: function () {
appWidget.setMainInfo();
appWidget.setContent();
},
setMainInfo: function(){
m.btnC = $(s.btnClass);
m.parent = $(s.btnClass).parent();
b.oWidth = parseInt( m.btnC.outerWidth(true) );
b.width = parseInt( m.btnC.width() );
b.margin = parseInt( m.btnC.css("margin").replace("px",'') );
m.iWidth = parseInt( m.parent.innerWidth() );
m.width = parseInt( m.parent.width() );
m.count = parseInt( m.btnC.length );
m.inRow = parseInt( Math.floor( parseInt( m.parent.width() ) / b.oWidth ) );
m.rows = parseInt( Math.ceil( m.count / m.inRow ) );
m.rowWidth = parseInt( b.oWidth * m.inRow );
m.espace = ((m.width - m.rowWidth) / m.inRow) / 2;
b.nMargin = parseInt( b.margin + ( ((m.width - m.rowWidth) / m.inRow) / 2 ) );
console.log(b.margin + m.espace);
},
setContent: function(){
m.btnC.css({ "margin-left": b.margin + m.espace, "margin-right": b.margin + m.espace })
},
bindUIActions: function() {
$(s.btnClass).click(function() {
console.log(this.id);
});
},
}
它必须在这一行,如果我评论该行不会改变回来
m.btnC.css({ "margin-left": b.margin + m.espace, "margin-right": b.margin + m.espace })
我尝试了各种stuf但不起作用:( 它会对我有所帮助,节省时间,非常感谢