我已经尝试了好几天:
我遇到的问题:
请帮忙!谢谢!
jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);
var h,
w,
sliderWidth;
function resizeFrame() {
h = $(window).height();
w = $(window).width(); // assign value to variable
sliderWidth = (w * 10);
$("div.slider").css('width',sliderWidth);
$("div.pane").css('width',w);
}
/************ JS CONSTRUCTOR ************/
function Slider(container, nav) {
this.container = container;
this.nav = nav;
this.panes = this.container.find('div.pane');
this.paneWidth = w; // referencing variable
this.panesLength = this.panes.length;
this.current = 0;
console.log('pane width = ' + w);
}
答案 0 :(得分:0)
您可以在构造函数中定义全局变量。
function resizeFrame() {
h = $(window).height();
w = $(window).width(); // assign value to variable
sliderWidth = (w * 10);
$("div.slider").css('width',sliderWidth);
$("div.pane").css('width',w);
}
jQuery.event.add(window, "load", resizeFrame);
jQuery.event.add(window, "resize", resizeFrame);
/************ JS CONSTRUCTOR ************/
function Slider(container, nav) {
h = typeof(h) == 'undefined' ? null : h;
w = typeof(w) == 'undefined' ? null : w;
sliderWidth = typeof(sliderWidth) == 'undefined' ? null : sliderWidth;
this.container = container;
this.nav = nav;
//this.panes = this.container.find('div.pane');
this.paneWidth = w; // referencing variable
//this.panesLength = this.panes.length;
this.current = 0;
console.log('pane width = ' + w);
}
new Slider();