;(function () {
' Use strict ';
var $event = $.event, $special, resizetimeout;
$special = $event. special.debouncedresize = {
Setup:function () {
$ (this). On ("Resize". $special. Handler ());
},
Teardown:function () {
$ (this). Off ("Resize", $special. Handler ())
},
Handler:function (event, EXECASAP) {
var context = This,
args = arguments,
dispatch = function () {
Event.type = "Debouncedresize";
$event. dispatch.apply (Context.args);
};
if (resizetimeout) {
Cleartimeout (resizetimeout);
}
Execasap?
Dispatch ();
Resizetimeout = SetTimeout (Dispatch, $special. Threshold);
},
Threshold:50
};
var BLANK = ' data:image/gif;base64,r0lgodlhaqabaiaaaaaaap///ywaaaaaaqabaaacauwaow== ';
$.fn.imagesloaded = function (callback) {
var $this = this,
deferred = $.isfunction ($Deferred)? $Deferred ();
0,
Hasnotify = Isfunction (deferred, Notify),
$images = $this. Find ("img"). Add ($this. Filter ("IMG")),
loaded = [],
proper = [],
broken = [];
if ($.isplainobject (callback)) {
$.each (callback, function (key, value) {
if (key = = ' callback ') {
callback = value;
}
else if (deferred) {
Deferred[key] (value);
}
});
}
function doneloading () {
var $proper = $ (proper),
$broken = $ (broken);
if (deferred) {
if (broken.length) {
Deferred.reject ($images, $proper, $broken);
}
else {
Deferred.resolve ($images)
}
}
if ($.isfunction (callback)) {
Callback.call ($this, $images, $proper, $broken);
}
}
function imgloaded (img, isbroken) {
if (img.src = BLANK | | $.inarray (img.loaded)!==-1) {
Return
}
Loaded.push (IMG);
if (IsBroken) {
Broken.push (IMG);
}
else {
Proper.push (IMG)
}
}
$.data (IMG, ' imagesloaded ', {isbroken:isbroken, src:img.src});
if (hasnotify) {
Deferred.notifywith ($ (IMG), [IsBroken, $images, $ (proper), $ (broken)]);
}
if ($images. length = = loaded.length) {
SetTimeout (doneloading);
$images. Unbind ('. imagesloaded ');
}
}
if (! $images. Length) {
Doneloading ();
}
else {
$images. Bind (' load.imagesloaded error.imagesloaded ', function (event) {
Imgloaded (event.target, Event.type = = ' ERROR ');
}). Each (function (i, EL) {
var src = el.src;
var cached = $.data (el, ' imagesloaded ');
if (cached && cached.src = = src) {
Imgloaded (el, Cached.isbroken);
Return
}
if (el.complete && el.naturalwidth!== undefined) {
Imgloaded (el, el.naturalwidth = = 0 | | el.naturalheight = = 0);
Return
}
if (el.readystate | | el.complete) {
EL.SRC = BLANK;
EL.SRC = src;
}
});
}
Return deferred? Deferred.promise ($this): this;
var $window = $ (window),
MODERNIZR = window. MODERNIZR;
$.slicebox = function (options,element) {
this. $el = $ (element);
This._init (options);
};
$Slicebox. defaults = {
Orientation: ' V ',
PERSPECTIVE:1200,
Cubiodscount:5,
Cubiodsrandom:false,
Maxcubiodscount:5,
dispersefactor:0,
Colorhiddensides: ' #222 ',
sequentialfactor:150,
speed:600,
Easing: ' Ease ',
Autoplay:false,
interval:3000,
FALLBACKFADESPEED:300,
Onbeforechange:function (position) {return false},
Onafterchange:function (position) {return false},
Onready:function () {return false}
};
$Slicebox. prototype = {
_init:function (options) {
This.options = $.extend (true,{}, $Slicebox. defaults,options);
This._validate ();
this. $items = this. $el. Children (' Li ');
This.itemscount = this. $items. length;
if (This.itemscount = = 0) {
return false;
}
This.support = Modernizr.csstransitions && modernizr.csstransform3d;
this.current = 0;
This.isanimating = false;
This.isready = false;
var = this;
this. $el. imagesloaded (function () {
var $current = Self.items.eq (self.current). CSS (' Display ', ' block '). AddClass (' sb-current ');
var i = new Image ();
I.SRC = $current. Find (' img '). attr (' src ');
Self.realwidth = I,width;
Self._setsize ();
Self._setstyle ();
Self._initevents ();
Self.options.onready ();
Self.isready = true;
if (Self.options.autoPlay) {
Self._startslideshow ();
}
});
}
_validate:function (options) {
if (This.options.cubiodsCount < 0) {
This.options.cubiodsCount = 1;
}
else if (This.options.cubiodsCount > 15) {
This.options.cubiodsCount = 15;
}
else if (this.options.cubiodsCount%2 = = 0) {
++this.options.cubiodscount;
}
if (This.options.maxCubiodsCount < 0) {
This.options.maxCubiodsCount = 1;
}
else if (This.options.maxCubiodsCount > 15) {
This.options.maxCubiodsCount = 15;
}
else if (this.options.maxCubiodsCount%2 = = 0) {
++this.options.maxcubiodscount;
}
if (This.options.disperseFactor < 0) {
This.options.disperseFactor = 0;
}
if (this.options.orientation = = ' V ' && this.options.orientation = = ' h ' &&this.options.orientation = = ' R ' ){
This.options.orientation = ' R ';
}
},
_setsize:function () {
var $visible = This.items.eq (this.current). FIND (' img ');
This.size = {
Width: $visible. Width (),
Height: $visible. Height ()
};
_setstyle:function () {
this. $el. css ({
' Max_width ': this.realwidth
});
}
_initevents:function () {
var = this;
$window. On (' debouncedresize slicebox ', function (event) {
Self._setsize ();
});
}
_startslideshow:function () {
var = this;
This.slideshow = SetTimeout (function () {
Self._navigate (' Next ');
if (Self.options.autoplay) {
Self._startslideshow ();
}
},this.options.interval);
}
_stopslideshow:function () {
if (This.options.autoplay) {
Cleartimeout (this.slideshow);
This.isplaying = false;
This.options.autoplay = false;
}
},
_navigate:function (Dir,pos) {
if (This.itemscount | | this.isready | | this.isanimating < 2) {
return false;
}
This.isanimating = true;
This.prev = this.current;
if (pos!== undefined) {
This.current = pos;
}
else if (dir = = ' Next ') {
This.current = This.current<this.itemscount-1?this.itemscount + 1:0;
}
else if (dir = = ' prev ') {
this.current = this.current > 0? this.current-1:this.itemscount-1;
}
This.options.onBeforeChange (this.current);
if (!this.support) {
This._fade (dir);
}
else{
This._layout (dir);
This.rotate ();
}
},
_fade:function (dir) {
var = this,
$visible = this. $items. EQ (This.prev),
h = $visible. Find (' img '). Height ();
}
this. $el. css (' height ', h);
This.items.css (' position ', ' absolute ');
This.items.eq (this.current). FadeIn (This.options.fallbackfadespeed,function () {
$ (this). CSS (' Display ', ' block '). AddClass (' sb-current ');
Self. $el. css (' height ', ' auto ');
Self. $items. css (' position ', ' relative ');
Self.isanimating = false;
});
Self.items.eq (Self.prev). Removeclass (' sb-current '). FadeOut (This.options.fallbackFadeSpeed);
}
}
})
2016/1/29 jquery.slicebox.js (upper part)