Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
全屏jQuery插件_Jquery_Resize_Window - Fatal编程技术网

全屏jQuery插件

全屏jQuery插件,jquery,resize,window,Jquery,Resize,Window,我编写了一个jQuery插件,它将DOM大小设置为窗口大小。当我调整窗口大小时,我想跟随它,但它不起作用。代码如下: (function( $ ){ $.fn.fullScreen = function() { return this.each(function() { $(this).css({ "width" : $(window).width(), "height" : $(window).height()

我编写了一个jQuery插件,它将DOM大小设置为窗口大小。当我调整窗口大小时,我想跟随它,但它不起作用。代码如下:

(function( $ ){

  $.fn.fullScreen = function() {

    return this.each(function() {
        $(this).css({
            "width" : $(window).width(),
            "height" : $(window).height()
        })
        $(window).resize(function() {
            $(this).css({
                "width" : $(window).width(),
                "height" : $(window).height()
            })
        })
    });

  };
})( jQuery );
在您的代码中,windows resize事件中的$(this)指的是windows。尝试:

(function( $ ){

  $.fn.fullScreen = function() {

    return this.each(function() {
        var self = $(this);
        $(this).css({
            "width" : $(window).width(),
            "height" : $(window).height()
        })
        $(window).resize(function() {
            self.css({
                "width" : $(window).width(),
                "height" : $(window).height()
            })
        })
    });

  };
})( jQuery );

需要插件吗?CSS:
.full-screen{display:block;height:100%;left:0;position:fixed;top:0;width:100%;}
JS:
$(…).addClass('full-screen')