gpt4 book ai didi

jquery - 结合 onload 和 onresize (jQuery)

转载 作者:行者123 更新时间:2023-12-03 21:27:08 25 4
gpt4 key购买 nike

我想在加载和调整大小时调用该函数。

有没有更好的方法来更紧凑地重写它?

$('.content .right').width($(window).width() - (480));
$(window).resize(function(e) {
$('.content .right').width($(window).width() - (480));
});

最佳答案

您可以单独绑定(bind)到resize事件,并在加载时自动触发该事件:

// 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() 调用将在加载时运行此代码。

关于jquery - 结合 onload 和 onresize (jQuery),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1974788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com