window.resize函数,我做错了什么?

我有一个脚本只能在高于980的分辨率下工作。我写了值if($(window).width()> 980)但它不起作用。 更确切地说是工作,但不正确。 当我打开网站最初是在一个小的解决方案,脚本不能按预期工作,但当你提高分辨率,他再次无法工作,不应该是什么。 相反,如果最初以高分辨率打开,那么脚本正在运行,如果是减少窗口而不是再次停止工作。 我究竟做错了什么?

这是脚本的原始版本

(function ($) { $.fn.hoverfold = function (args) { this.each(function () { $(this).children('.view').each(function () { var $item = $(this), img = $item.children('img').attr('src'), struct = '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; var $struct = $(struct); $item.find('img').remove().end() .append($struct).find('div.slice').css('background-image', 'url(' + img + ')').prepend($('')); }); }); }; }) (jQuery);

这是我写的代码。

 var hoverhold = function () { if ($(window).width() > 980) { (function ($) { $.fn.hoverfold = function (args) { this.each(function () { $(this).children('.view').each(function () { var $item = $(this), img = $item.children('img').attr('src'), struct = '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; struct += '
'; var $struct = $(struct); $item.find('img').remove().end() .append($struct).find('div.slice').css('background-image', 'url(' + img + ')').prepend($('')); }); }); }; }) (jQuery); } else { } }; hoverhold(); $(window).resize(hoverhold);