本文介绍了结合onload和onresize(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在加载以及调整大小时调用该函数.
I want to call the function on load as well as on resize.
是否有更好的方法来更紧凑地重写它?
Is there a better way to rewrite this more compactly?
$('.content .right').width($(window).width() - (480));
$(window).resize(function(e) {
$('.content .right').width($(window).width() - (480));
});
推荐答案
您可以单独绑定到resize
事件,并在加载时自动触发此事件:
You can bind to the resize
event alone, and trigger this event automatically upon load:
// Bind to the resize event of the window object
$(window).on("resize", function () {
// Set .right's width to the window width minus 480 pixels
$(".content .right").width( $(this).width() - 480 );
// Invoke the resize event immediately
}).resize();
最后一个.resize()
调用将在加载时运行此代码.
The last .resize()
call will run this code upon load.
这篇关于结合onload和onresize(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!