Javascript jQuery函数在调整窗口大小之前不会启动 我有一个基础轨道图像滑动器,直到你调整浏览器窗口大小才显示出来。空间是空的,直到你仅仅改变一个像素的窗口大小。基金会正在计算滑块的飞行高度,但是当页面第一次加载时,容器上没有高度设置。
我还有一个导航条,在我调整窗口大小之前,它不会将自身校正到计算的宽度 这是导航条形码:Javascript jQuery函数在调整窗口大小之前不会启动 我有一个基础轨道图像滑动器,直到你调整浏览器窗口大小才显示出来。空间是空的,直到你仅仅改变一个像素的窗口大小。基金会正在计算滑块的飞行高度,但是当页面第一次加载时,容器上没有高度设置。,javascript,jquery,ember.js,zurb-foundation,Javascript,Jquery,Ember.js,Zurb Foundation,我还有一个导航条,在我调整窗口大小之前,它不会将自身校正到计算的宽度 这是导航条形码: Ew.ApplicationView = Ember.View.extend({ didInsertElement: function() { $(".nav").width($(window).width() - 406); $(".subnav").width($(window).width() - 396); return $(window).resize(function(
Ew.ApplicationView = Ember.View.extend({
didInsertElement: function() {
$(".nav").width($(window).width() - 406);
$(".subnav").width($(window).width() - 396);
return $(window).resize(function() {
$(".nav").width($(window).width() - 406);
return $(".subnav").width($(window).width() - 396);
});
}
});
和滑块初始化代码:
Ew.OrbitSliderComponent = Ember.Component.extend({
initOrbit: function() {
$(document).foundation('orbit', {
stack_on_small: true;
navigation_arrows: false;
variable_height: true;
});
}.on('didInsertElement')
});
是什么导致jQuery函数在窗口调整大小之前不启动 可能是那些部分在说:
return $(window).resize(function() {
如果它不是$(窗口)。调整大小是$(文档)。加载呢
从jQuery文档:
/*The load event is sent to an element when it and all sub-elements have been
completely loaded. This event can be sent to any element associated with a
URL: images, scripts, frames, iframes, and the window object.*/
可能是那些部分在说:
return $(window).resize(function() {
如果它不是$(窗口)。调整大小是$(文档)。加载呢
从jQuery文档:
/*The load event is sent to an element when it and all sub-elements have been
completely loaded. This event can be sent to any element associated with a
URL: images, scripts, frames, iframes, and the window object.*/
我不完全理解为什么会发生这种情况,但它似乎与
.nav
和.subnav
的大小有关,对吗?我认为这些元素的初始大小确定得太早了。请尝试以下方法:
Ew.ApplicationView = Ember.View.extend({
didInsertElement: function() {
Ember.run.scheduleOnce('afterRender', this, function(){
$(".nav").width($(window).width() - 406);
$(".subnav").width($(window).width() - 396);
return $(window).resize(function() {
$(".nav").width($(window).width() - 406);
return $(".subnav").width($(window).width() - 396);
});
}
}
});
这将使您的逻辑在Ember执行所有渲染之后运行。实际上,didInsertElement只保证在给定视图的根元素存在时执行。子元素或子视图不必存在请查看我的,以获得解释和更优雅的方法,避免代码中出现这种不吸引人的嵌套。我不完全理解为什么会发生这种情况,但它似乎与大小
.nav
和subnav
有关,对吗?我认为这些元素的初始大小确定得太早了。请尝试以下方法:
Ew.ApplicationView = Ember.View.extend({
didInsertElement: function() {
Ember.run.scheduleOnce('afterRender', this, function(){
$(".nav").width($(window).width() - 406);
$(".subnav").width($(window).width() - 396);
return $(window).resize(function() {
$(".nav").width($(window).width() - 406);
return $(".subnav").width($(window).width() - 396);
});
}
}
});
这将使您的逻辑在Ember执行所有渲染之后运行。实际上,didInsertElement只保证在给定视图的根元素存在时执行。子元素或子视图不必存在请查看my,以获得解释和更优雅的方法,避免在代码中出现这种不吸引人的嵌套。一个简单的技巧是将
.resize()
函数链接两次:
return $(window).resize(function() {
$(".nav").width($(window).width() - 406);
return $(".subnav").width($(window).width() - 396);
}).resize(); // Resize() onload
您可以看到无链接()和有链接()之间的区别。一个简单的技巧是将
.resize()函数链接两次:
return $(window).resize(function() {
$(".nav").width($(window).width() - 406);
return $(".subnav").width($(window).width() - 396);
}).resize(); // Resize() onload
您可以看到无链接()和有链接()之间的区别。不过我需要resize()函数,因为它是响应性的。它不会在加载时调整大小()。谢谢。不过我需要resize()函数,因为它响应速度快。它不会在加载时调整大小()。谢谢你。