简体   繁体   English

在页面调整大小时重新启动用户定义的jquery函数

[英]Reinitiate user defined jquery function on page resize

I've inherited some code from a previous developer who is now no longer contactable. 我已经从以前无法联系的开发人员那里继承了一些代码。 I'm trying to get the function to reinitialize when the page is resized, but can't seem to get it to do so. 我正在尝试让函数在页面调整大小时重新初始化,但似乎无法做到这一点。

I'm a bit of a jQuery noob, which doesn't help. 我有点jQuery菜鸟,这没有帮助。

The function is below: 该功能如下:

(function ($) {
    $.fn.setWidth = function (o) {
        var vWidth = $("#wrapper").outerWidth(false) - 40;
    };
})(jQuery);

I've tried the following to reinitialize it when the page resizes, but currently nothing happens. 我尝试了以下方法以在页面调整大小时重新初始化它,但是目前没有任何反应。 No errors are generated either. 也不产生错误。

$(window).resize(function() {
     $().setWidth();
});

Any pointers would be gratefully received. 任何指针将不胜感激。

-Edit- -编辑-

Sorry, I should point out there is more code within the setWidth function, but I trimmed it out. 抱歉,我应该指出setWidth函数中还有更多代码,但是我将其修剪掉了。 I'm just trying to get the main function to reinitialize on resize. 我只是想让主函数在调整大小时重新初始化。

If you have a function function pageResize(){ that does the var vWidth = $("#wrapper").outerWidth(false)-40; 如果您有一个函数function pageResize(){ ,该函数执行var vWidth = $("#wrapper").outerWidth(false)-40; code, you can then recall that on page resize. 代码,然后您就可以在调整页面大小时重新调用该代码。

So: 所以:

function pageResize(){
     var vWidth = $("#wrapper").outerWidth(false)-40;
}

$(window).resize(function() {
    pageResize();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM