img ( ).
CSS ɡ Ϻ (jQuery plugins) Fullscreen .
* cover:background-size ѡ background.
Anonymous function

(Anonymous function) jQuery $ ( closure) ( ) $ .
(function($) { // })(jQuery)
1
2
3
(function($) {
//
})(jQuery)


Method

(fullBg) :
(function($) { $.fn.fullBg = function(){ // . }; })(jQuery)
1
2
3
4
5
6
7
(function($) {
$.fn.fullBg = function(){
// .


};
})(jQuery)


$.fn $.prototype Method object ($).


:
(function($) { $.fn.fullBg = function(){ return this.each(function(){ var _this = $(this), _width = _this.width(), _height = _this.height(), _widthw = $(window).width(), _heightw = $(window).height(); if(_width/_widthw > _height/_heightw){ _this.css({ 'height':'100%', 'width':'auto' }); }else{ _this.css({ 'width':'100%', 'height':'auto' }); } }); }; })(jQuery)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(function($) {
$.fn.fullBg = function(){

return this.each(function(){
var _this = $(this),
_width = _this.width(),
_height = _this.height(),
_widthw = $(window).width(),
_heightw = $(window).height();

if(_width/_widthw > _height/_heightw){
_this.css({
'height':'100%',
'width':'auto'
});
}else{
_this.css({
'width':'100%',
'height':'auto'
});
}

});



};
})(jQuery)


(Anonymous function) each() :

  • : _width ɡ _height ɡ_widthw ͡ _heightw .
  • ء .. ..
    Fullscreen .

.fullbg{ position: fixed; left: 0; top: 0; } /* fullbg . */
1
2
3
4
5
6
7
8
.fullbg{
position: fixed;
left: 0;
top: 0;
}
/*
fullbg .
*/


ǡ :
$('.fullbg').fullBg();
1
$('.fullbg').fullBg();


fullbg
<img src="test.jpg" class="fullbg" >
1
<img src="test.jpg" class="fullbg" >


Fullscreen .