全屏jQuery插件
我编写了一个jQuery插件,它将DOM大小设置为窗口大小。当我调整窗口大小时,我想跟随它,但它不起作用。代码如下:全屏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()
(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')代码>