/* 2019-1-18
* superslide v3.0 alpha开发版
* 轻松解决网站大部分特效展示问题
* 详尽信息请看官网:http://www.superslide2.com/
*
* copyright 2011-2018, 大话主席
*
* 请尊重原创,保留头部版权
* 在保留版权的前提下可应用于个人或商业用途
* v3.0:
1、修复 mouseoverstop 和 autoplay均为false下,点击切换按钮后会自动播放bug;
2、intertime默认值改为4000;
3、vis默认值改为"auto"
4、scroll默认值改为"auto"
5、增加参数 responsive -- 默认值ture,是否开启响应式功能
6、增加参数 responsivefun -- 响应式回调函数
7、增加参数 responsivefuntime -- 默认值100,单位毫秒,外框宽度改变(触发响应式)时回调函数执行间隔
8、增加参数 autoheight -- 默认值true,自动适配内容高度,常用于移动端,effect:"left或leftloop",vis:1,scroll:1时有效
9、增加参数 cantouch -- 默认值"auto",移动端有效;是否带触摸拖拽效果;可选"auto"|true|false;auto情况下是除了fade、fold、slidedown不带触摸,其它都带
10、重新设计"fold"的实现方式,不再需要计算宽高,现在可以自适应高度
11、新增外置方法:
play() -- 播放
pause() -- 暂停
prev() -- 上一页
next() -- 下一页
goto(int) -- 跳到第int页
refresh() -- 刷新效果
reset() -- 重置效果
getindex() -- 获取当前页码
getpages() -- 获取总页数
clearstyle() -- 清除插件加入的style
destroyinter() -- 销毁setinterval和settimeout
destroyevents() -- 销毁事件绑定
destroy() -- 销毁插件(clearstyle() + destroyinter() + destroyevents())
使用方式:
执行slide后会返回superslide对象集合;
例如:
var ss = $(".slider").slide({ .... });
现在想设置第二个".slider"暂停,执行代码为: ss[1].pause();
*/
(function ($, win) {
$.fn.slide = function (options) {
$.fn.slide.defaults = {
type: "slide",
effect: "fade",
autoplay: false,
delaytime: 500,
intertime: 4000,
triggertime: 150,
defaultindex: 0,
titcell: ".hd li",
maincell: ".bd",
targetcell: null,
trigger: "mouseover",
scroll: "auto",
vis: "auto",
titonclassname: "on",
autopage: false,
prevcell: ".prev",
nextcell: ".next",
pagestatecell: ".pagestate",
opp: false,
pnloop: true,
easing: "swing",
startfun: null,
endfun: null,
switchload: null,
playstatecell: ".playstate",
mouseoverstop: true,
defaultplay: true,
returndefault: false,
responsive: true,
responsivefun: null,
responsivefuntime: 100,
autoheight: true,
cantouch: "auto"
};
var ary = [];
var createobj = function (opts, slider) {
var _this = this;
var effect = opts.effect;
var prevbtn = $(opts.prevcell, slider);
var nextbtn = $(opts.nextcell, slider);
var pagestate = $(opts.pagestatecell, slider);
var playstate = $(opts.playstatecell, slider);
var navobj = $(opts.titcell, slider); //导航子元素结合
var navobjsize = navobj.length;
var conbox = $(opts.maincell, slider); //内容元素父层对象
var conboxsize = conbox.children().length;
var sload = opts.switchload;
var tarobj = $(opts.targetcell, slider);
/*字符串转换*/
var index = parseint(opts.defaultindex);
var delaytime = parseint(opts.delaytime);
var intertime = parseint(opts.intertime);
var triggertime = parseint(opts.triggertime);
var scroll = isnan(opts.scroll) ? "auto" : parseint(opts.scroll);
var vis = isnan(opts.vis) ? "auto" : parseint(opts.vis);
var autoplay = (opts.autoplay == "false" || opts.autoplay == false) ? false : true;
var opp = (opts.opp == "false" || opts.opp == false) ? false : true;
var autopage = (opts.autopage == "false" || opts.autopage == false) ? false : true;
var pnloop = (opts.pnloop == "false" || opts.pnloop == false) ? false : true;
var mouseoverstop = (opts.mouseoverstop == "false" || opts.mouseoverstop == false) ? false : true;
var defaultplay = (opts.defaultplay == "false" || opts.defaultplay == false) ? false : true;
var returndefault = (opts.returndefault == "false" || opts.returndefault == false) ? false : true;
var cantouch = opts.cantouch;
//触摸相关
var supporttouch = !!("ontouchstart" in window || window.navigator.msmaxtouchpoints);
if (cantouch == "auto") {
if (("left leftloop leftmarquee top toploop topmarquee").indexof(effect) != -1) {
cantouch = true;
} else {
cantouch = false;
}
} else {
cantouch = (opts.cantouch == "false" || opts.cantouch == false) ? false : true;
}
cantouch = (cantouch && supporttouch) ? true : false;
var touchstart = supporttouch ? 'touchstart' : 'touchstart';
var touchmove = supporttouch ? 'touchmove' : 'touchmove';
var touchend = supporttouch ? 'touchend' : 'touchend';
// var touchstart = supporttouch ? 'touchstart' : 'mousedown';
// var touchmove = supporttouch ? 'touchmove' : 'mousemove';
// var touchend = supporttouch ? 'touchend' : 'mouseup';
//内部使用变量
var slideh = 0;
var slidew = 0;
var selfw = 0;
var selfh = 0;
var easing = opts.easing;
var inter = null; //autoplay-setinterval
var titst = null; //titcell-settimeout
var rtnst = null; //返回默认-settimeout
var pnst = null; //前后按钮长安-settimeout
var resizest = null; //win响应式-settimeout
var titon = opts.titonclassname;
var onindex = navobj.index(slider.find("." + titon));
var oldindex = index = onindex == -1 ? index : onindex;
var defaultindex = index;
var scrollnum = 0;
var _ind = index;
var clonenum = 0;
var _tar;
var ismarq = effect == "leftmarquee" || effect == "topmarquee" ? true : false;
var islefteffectfortouch = ("left leftloop leftmarquee fade fold").indexof(effect) == -1 ? false : true;
var istopeffectfortouch = ("top toploop topmarquee fade fold").indexof(effect) == -1 ? false : true;
var islefteffect = ("left leftloop leftmarquee").indexof(effect) == -1 ? false : true;
var istopeffect = ("top toploop topmarquee").indexof(effect) == -1 ? false : true;
var conboxparwidth = conbox.parent().width();
var conboxparheight = conbox.parent().height();
var responsivecallback = function () {
if ($.isfunction(opts.responsivefun)) {
opts.responsivefun(index,
navobjsize,
slider,
$(opts.titcell, slider),
conbox,
tarobj,
prevbtn,
nextbtn);
}
};
var startcallback = function () {
if ($.isfunction(opts.startfun)) {
opts.startfun(index, navobjsize, slider, $(opts.titcell, slider), conbox, tarobj, prevbtn, nextbtn);
}
};
var endcallback = function () {
if ($.isfunction(opts.endfun)) {
opts.endfun(index, navobjsize, slider, $(opts.titcell, slider), conbox, tarobj, prevbtn, nextbtn);
}
};
var reseton = function () {
navobj.removeclass(titon);
if (defaultplay) {
navobj.eq(defaultindex).addclass(titon);
}
};
//绑定titcell事件
var titcellevent = function (o) {
if (opts.trigger == "mouseover") {
o.hover(function () {
var hoverind = o.index(this);
titst = settimeout(function () {
index = hoverind;
doplay();
resetinter();
},
opts.triggertime);
},
function () { cleartimeout(titst) });
} else {
o.click(function () {
index = o.index(this);
doplay();
resetinter();
});
}
};
//单独处理菜单效果
if (opts.type == "menu") {
if (defaultplay) {
navobj.removeclass(titon).eq(index).addclass(titon);
}
navobj.hover(
function () {
_tar = $(this).find(opts.targetcell);
var hoverind = navobj.index($(this));
titst = settimeout(function () {
index = hoverind;
navobj.removeclass(titon).eq(index).addclass(titon);
startcallback();
switch (effect) {
case "fade":
_tar.stop(true, true).animate({ opacity: "show" },
delaytime,
easing,
endcallback);
break;
case "slidedown":
_tar.stop(true, true).animate({ height: "show" },
delaytime,
easing,
endcallback);
break;
}
},
opts.triggertime);
},
function () {
cleartimeout(titst);
switch (effect) {
case "fade":
_tar.animate({ opacity: "hide" }, delaytime, easing);
break;
case "slidedown":
_tar.animate({ height: "hide" }, delaytime, easing);
break;
}
}
);
if (returndefault) {
slider.hover(function () { cleartimeout(rtnst); },
function () { rtnst = settimeout(reseton, delaytime); });
}
return;
}
//切换加载
var doswitchload = function (objs) {
var changeimg = function (t) {
for (var i = t; i < (vis + t); i++) {
objs.eq(i).find("img[" + sload + "]").each(function () {
var _t = $(this);
_t.attr("src", _t.attr(sload));
if (conbox.find(".clone")[0]) { //如果存在.clone
var chir = conbox.children();
for (var j = 0; j < chir.length; j++) {
chir.eq(j).find("img[" + sload + "]").each(function () {
if ($(this).attr(sload) == _t.attr("src")) {
$(this).attr("src", $(this).attr(sload));
}
});
}
}
});
}
};
switch (effect) {
case "fade":
case "fold":
case "top":
case "left":
case "slidedown":
changeimg(index * scroll);
break;
case "leftloop":
case "toploop":
changeimg(clonenum + scrollnum(_ind));
break;
case "leftmarquee":
case "topmarquee":
var curs = effect == "leftmarquee"
? conbox.css("left").replace("px", "")
: conbox.css("top").replace("px", "");
var slidet = effect == "leftmarquee" ? slidew : slideh;
var mnum = clonenum;
if (curs % slidet != 0) {
var curp = math.abs(curs / slidet ^ 0);
if (index == 1) {
mnum = clonenum + curp;
} else {
mnum = clonenum + curp - 1;
}
}
changeimg(mnum);
break;
}
}; //doswitchload end
//初始化
var setinit = function () {
var tempindex = index;
if (true) {
}
selfw = 0;
selfh = 0;
conbox.children().each(function () { //取最大值
if ($(this).width() > selfw) {
selfw = $(this).width();
slidew = $(this).outerwidth(true);
}
if ($(this).height() > selfh) {
selfh = $(this).height();
slideh = $(this).outerheight(true);
}
});
if (opts.vis == "auto") {
if (istopeffect) {
vis = parseint(conboxparheight / slideh);
} else {
vis = parseint(conboxparwidth / slidew);
}
vis = vis == 0 ? 1 : vis;
}
if (opts.scroll == "auto") {
scroll = vis;
}
clonenum = conboxsize >= vis ? (conboxsize % scroll != 0 ? conboxsize % scroll : scroll) : 0;
//处理分页
if (navobjsize == 0) {
navobjsize = conboxsize;
}
//只有左右按钮
if (ismarq) {
navobjsize = 2;
tempindex = 0;
}
if (autopage) {
if (conboxsize >= vis) {
if (effect == "leftloop" || effect == "toploop") {
navobjsize = conboxsize % scroll != 0 ? (conboxsize / scroll ^ 0) + 1 : conboxsize / scroll;
}
//else if (ismarq){ navobjsize=2 }
else {
var temps = conboxsize - vis;
navobjsize = 1 + parseint(temps % scroll != 0 ? (temps / scroll + 1) : (temps / scroll));
if (navobjsize <= 0) {
navobjsize = 1;
}
}
} else {
navobjsize = 1;
}
$(opts.titcell, slider).empty();
var str = "";
if (opts.autopage == true || opts.autopage == "true") {
for (var i = 0; i < navobjsize; i++) {
str += "
" + (i + 1) + "";
}
} else {
for (var i = 0; i < navobjsize; i++) {
str += opts.autopage.replace("$", (i + 1));
}
}
$(opts.titcell, slider).html(str);
navobj = $(opts.titcell, slider).children(); //重置导航子元素对象
navobj.eq(index).addclass(titon);
titcellevent(navobj);
}
if (conboxsize >= vis) { //当内容个数少于可视个数,不执行效果。
//console.log(vis+"|"+clonenum);
var cloneele = function () {
var _chr = conbox.children();
for (var i = 0; i < vis; i++) {
_chr.eq(i).clone().addclass("clone").appendto(conbox);
}
for (var i = 0; i < clonenum; i++) {
_chr.eq(conboxsize - i - 1).clone().addclass("clone").prependto(conbox);
}
};
switch (effect) {
case "fold":
conbox.css({ "overflow": "hidden" }).children().css({
"width": "100%",
"float": "left",
"marginright": "-100%",
"display": "none"
});
break;
case "top":
conbox.wrap('')
.css({
"top": -(tempindex * scroll) * slideh,
"position": "relative",
"padding": "0",
"margin": "0"
}).children().css({ "height": selfh });
break;
case "left":
var visscope = isnan(opts.vis) ? opts.vis : vis * slidew + 'px';
conbox.wrap('');
conbox.css({
"width": conboxsize * slidew,
"left": -(tempindex * scroll) * slidew,
"position": "relative",
"overflow": "hidden",
"padding": "0",
"margin": "0"
}).children().css({ "float": "left", "width": selfw });
break;
case "leftloop":
case "leftmarquee":
cloneele();
var visscope = isnan(opts.vis) ? "100%" : vis * slidew + 'px';
conbox.wrap('');
conbox.css({
"width": (conboxsize + vis + 1 + clonenum) * slidew,
"position": "relative",
"overflow": "hidden",
"padding": "0",
"margin": "0",
"left": -(clonenum + tempindex * scroll) * slidew
}).children().css({ "float": "left", "width": selfw });
break;
case "toploop":
case "topmarquee":
cloneele();
conbox
.wrap('')
.css({
"height": (conboxsize + vis + clonenum) * slideh,
"position": "relative",
"padding": "0",
"margin": "0",
"top": -(clonenum + tempindex * scroll) * slideh
}).children().css({ "height": selfh });
break;
}
}
//针对leftloop、toploop的滚动个数
scrollnum = function (ind) {
var _tempcs = ind * scroll;
if (ind == navobjsize) {
_tempcs = conboxsize;
} else if (ind == -1 && conboxsize % scroll != 0) {
_tempcs = -conboxsize % scroll;
}
return _tempcs;
};
//pagestate.html( ""+(index+1)+"/"+navobjsize);
}; //setinit end
setinit();
responsivecallback();
//效果函数
var doplay = function (_setinit) {
// 当前页状态不触发效果
if (defaultplay && oldindex == index && !_setinit && !ismarq) {
return;
}
//处理页码
if (ismarq) {
if (index >= 1) {
index = 1;
} else if (index <= 0) {
index = 0;
}
} else {
_ind = index;
if (index >= navobjsize) {
index = 0;
} else if (index < 0) {
index = navobjsize - 1;
}
}
//处理切换加载
if (sload != null) {
doswitchload(conbox.children());
}
startcallback();
//处理targetcell
if (tarobj[0]) {
_tar = tarobj.eq(index);
if (sload != null) {
doswitchload(tarobj);
}
if (effect == "slidedown") {
tarobj.not(_tar).stop(true, true).slideup(delaytime);
_tar.slidedown(delaytime,
easing,
function () {
if (!conbox[0]) {
endcallback();
}
});
} else {
tarobj.not(_tar).stop(true, true).hide();
_tar.animate({ opacity: "show" },
delaytime,
function () {
if (!conbox[0]) {
endcallback();
}
});
}
}
if (conboxsize >= vis) { //当内容个数少于可视个数,不执行效果。
switch (effect) {
case "fade":
conbox.children().stop(true, true).eq(index).animate({ opacity: "show" },
delaytime,
easing,
function () { endcallback() }).siblings().hide();
break;
case "fold":
conbox.children().stop(true, true).eq(index)
.animate({ opacity: "show" }, delaytime, easing, function () { endcallback() })
.siblings().animate({ opacity: "hide" }, delaytime, easing);
break;
case "top":
conbox.stop(true, false).animate({ "top": -index * scroll * slideh },
delaytime,
easing,
function () { endcallback() });
break;
case "left":
conbox.stop(true, false).animate({ "left": -index * scroll * slidew },
delaytime,
easing,
function () { endcallback() });
break;
case "leftloop":
var __ind = _ind;
conbox.stop(true, true).animate({ "left": -(scrollnum(_ind) + clonenum) * slidew },
delaytime,
easing,
function () {
if (__ind <= -1) {
conbox.css("left", -(clonenum + (navobjsize - 1) * scroll) * slidew);
} else if (__ind >= navobjsize) {
conbox.css("left", -clonenum * slidew);
}
endcallback();
});
break; //leftloop end
case "toploop":
var __ind = _ind;
conbox.stop(true, true).animate({ "top": -(scrollnum(_ind) + clonenum) * slideh },
delaytime,
easing,
function () {
if (__ind <= -1) {
conbox.css("top", -(clonenum + (navobjsize - 1) * scroll) * slideh);
} else if (__ind >= navobjsize) {
conbox.css("top", -clonenum * slideh);
}
endcallback();
});
break; //toploop end
case "leftmarquee":
var templeft = conbox.css("left").replace("px", "");
if (index == 0) {
conbox.animate({ "left": ++templeft },
0,
function () {
if (conbox.css("left").replace("px", "") >= 0) {
conbox.css("left", -conboxsize * slidew);
}
});
} else {
conbox.animate({ "left": --templeft },
0,
function () {
if (conbox.css("left").replace("px", "") <= -(conboxsize + clonenum) * slidew) {
conbox.css("left", -clonenum * slidew);
}
});
}
break; // leftmarquee end
case "topmarquee":
var temptop = conbox.css("top").replace("px", "");
if (index == 0) {
conbox.animate({ "top": ++temptop },
0,
function () {
if (conbox.css("top").replace("px", "") >= 0) {
conbox.css("top", -conboxsize * slideh);
}
});
} else {
conbox.animate({ "top": --temptop },
0,
function () {
if (conbox.css("top").replace("px", "") <= -(conboxsize + clonenum) * slideh) {
conbox.css("top", -clonenum * slideh);
}
});
}
break; // topmarquee end
} //switch end
}
navobj.removeclass(titon).eq(index).addclass(titon);
oldindex = index;
if (!pnloop) { //pnloop控制前后按钮是否继续循环
nextbtn.removeclass("nextstop");
prevbtn.removeclass("prevstop");
if (index == 0) {
prevbtn.addclass("prevstop");
}
if (index == navobjsize - 1) {
nextbtn.addclass("nextstop");
}
}
pagestate.html("" + (index + 1) + "/" + navobjsize);
// 自动适配高度
if (opts.autoheight && (effect == "left" || effect == "leftloop") && vis == 1 && scroll == 1) {
var curitem = conbox.children().not(conbox.find(".clone")).eq(index);
var pic = curitem.find("img");
var piccount = pic.length;
if (piccount <= 0) {
conbox.height(curitem.outerheight());
return;
}
pic.each(function () { //存在图片时监测图片高度
var img = $(this);
var imgint = setinterval(function () {
if (img.height() > 0) {
clearinterval(imgint);
piccount--;
if (piccount <= 0) {
conbox.height(curitem.outerheight());
}
}
},
50);
});
}
}; // doplay end
//初始化执行
if (defaultplay) {
doplay(true);
}
//返回默认状态
if (returndefault) {
slider.hover(function () { cleartimeout(rtnst) },
function () {
rtnst = settimeout(function () {
index = defaultindex;
if (defaultplay) {
doplay();
} else {
if (effect == "slidedown") {
_tar.slideup(delaytime, reseton);
} else {
_tar.animate({ opacity: "hide" }, delaytime, reseton);
}
}
oldindex = index;
},
300);
});
}
///自动播放函数
var setinter = function (time) {
inter = setinterval(function () {
opp ? index-- : index++;
doplay();
},
!!time ? time : intertime);
};
var setmarinter = function (time) { inter = setinterval(doplay, !!time ? time : intertime); };
// 处理mouseoverstop
var resetinter = function () {
if (!mouseoverstop && autoplay && !playstate.hasclass("pausestate")) {
clearinterval(inter);
setinter();
}
}; /* 修复 mouseoverstop 和 autoplay均为false下,点击切换按钮后会自动播放bug */
// 前后按钮函数
var nextfun = function () {
if (pnloop || index != navobjsize - 1) {
index++;
doplay();
if (!ismarq) {
resetinter();
}
}
};
var prevfun = function () {
if (pnloop || index != 0) {
index--;
doplay();
if (!ismarq) {
resetinter();
}
}
};
//处理playstate
var playstatefun = function () {
autoplay = true;
clearinterval(inter);
playstate.removeclass("pausestate");
ismarq ? setmarinter() : setinter();
};
var pausestatefun = function () {
autoplay = false;
clearinterval(inter);
playstate.addclass("pausestate");
};
//初始化自动播放
var setautoplay = function () {
if (autoplay) {
if (ismarq) {
opp ? index-- : index++;
setmarinter();
if (mouseoverstop) {
conbox.hover(pausestatefun, playstatefun);
}
} else {
setinter();
if (mouseoverstop) {
slider.hover(pausestatefun, playstatefun);
}
}
} else {
if (ismarq) {
opp ? index-- : index++;
}
playstate.addclass("pausestate");
}
};
setautoplay();
//绑定事件
var settrigger = function () {
playstate.click(function () { playstate.hasclass("pausestate") ? playstatefun() : pausestatefun() });
titcellevent(navobj);
//前后按钮事件
if (ismarq) {
nextbtn.mousedown(nextfun);
prevbtn.mousedown(prevfun);
//前后按钮长按10倍加速
if (pnloop) {
var mardown = function () {
pnst = settimeout(function () {
clearinterval(inter);
setmarinter(intertime / 10 ^ 0);
},
150);
};
var marup = function () {
cleartimeout(pnst);
clearinterval(inter);
setmarinter();
};
nextbtn.mousedown(mardown);
nextbtn.mouseup(marup);
prevbtn.mousedown(mardown);
prevbtn.mouseup(marup);
}
//前后按钮mouseover事件
if (opts.trigger == "mouseover") {
nextbtn.hover(nextfun, function () {});
prevbtn.hover(prevfun, function () {});
}
} else {
nextbtn.click(nextfun);
prevbtn.click(prevfun);
}
//触摸事件
if (cantouch) {
conbox.on(touchstart,
function (e) {
conbox.stop(1, 1);
clearinterval(inter);
conbox.find("a").click(function (e) { e.preventdefault() });
e = supporttouch ? e.originalevent.targettouches[0] : (e || window.event);
var distx,
disty,
ox,
oy,
ol,
ot;
var _this = $(this);
ol = this.offsetleft;
ot = this.offsettop;
ox = e.pagex;
oy = e.pagey;
var scrolly = false;
$(this).on(touchmove,
function (ev) {
e = supporttouch ? ev.originalevent.targettouches[0] : (ev || window.event);
distx = e.pagex - ox;
disty = e.pagey - oy;
scrolly = math.abs(distx) < math.abs(disty) ? true : false;
if (!scrolly && islefteffectfortouch) {
ev.preventdefault();
if (effect == "left" &&
((index == 0 && distx > 0) || (index >= navobjsize - 1 && distx < 0))) {
distx = distx * 0.4;
}
_this.css({ "left": ol + distx + "px" });
} else if (scrolly && istopeffectfortouch) {
ev.preventdefault();
if (effect == "top" &&
((index == 0 && disty > 0) || (index >= navobjsize - 1 && disty < 0))) {
disty = disty * 0.4;
}
_this.css({ "top": ot + disty + "px" });
}
});
$(this).on(touchend,
function (e) {
if (!distx) {
conbox.find("a").off("click");
} else if (!scrolly && islefteffectfortouch) {
if (math.abs(distx) > slidew / 10) {
distx > 0 ? index-- : index++;
if (effect == "left") {
index = index < 0 ? 0 : index;
index = index >= navobjsize ? navobjsize - 1 : index;
}
}
doplay(true);
} else if (scrolly && istopeffectfortouch) {
if (math.abs(disty) > slideh / 10) {
disty > 0 ? index-- : index++;
if (effect == "top") {
index = index < 0 ? 0 : index;
index = index >= navobjsize ? navobjsize - 1 : index;
}
}
doplay(true);
}
clearinterval(inter);
playstate.removeclass("pausestate");
if (autoplay) {
ismarq ? setmarinter() : setinter();
}
conbox.off(touchmove);
conbox.off(touchend);
});
});
}
};
settrigger();
// 为检测设备尺寸变化,清除一些附加样色和元素
var clear = function () {
conbox.stop(true, true);
if (conbox.parent().hasclass("tempwrap")) {
conbox.unwrap("tempwrap");
};
conbox.find(".clone").remove();
if (islefteffect) {
conbox.children().css({ "width": "", "float": "" });
conbox.css({ "width": "", "left": 0 });
} else if (istopeffect) {
conbox.children().css({ "height": "" });
conbox.css({ "height": "", "top": 0 });
}
};
//检测设备尺寸变化
var setresponsive = function () {
if (opts.responsive) {
var _vis;
var _conboxparwidth;
var _conboxparheight;
var orientationchange = function () {
responsivecallback();
_conboxparwidth = conbox.parent().width();
_conboxparheight = conbox.parent().height();
if (islefteffect && _conboxparwidth != conboxparwidth) { //外层宽度有变化才执行
conboxparwidth = _conboxparwidth;
//处理sload
/*
_vis = parseint( conbox.parent().width() / slidew );
vis = _vis;
if( opts.scroll=="auto" ){ scroll = vis }*/
clear();
setinit();
doplay(true);
} else if (istopeffect && _conboxparheight != conboxparheight) { //外层高度有变化才执行
conboxparheight = _conboxparheight;
clear();
setinit();
doplay(true);
}
};
$(win).resize(function () {
if (resizest) {
cleartimeout(resizest);
}
resizest = settimeout(orientationchange, opts.responsivefuntime);
});
}
};
setresponsive();
/*-- 外置api --*/
//清除所有附加元素和样色
this.clearstyle = function () {
if (conbox.parent().hasclass("tempwrap")) {
conbox.unwrap("tempwrap");
};
conbox.find(".clone").remove();
conbox.children().removeattr("style");
conbox.removeattr("style");
};
//销毁setinterval和settimeout
this.destroyinter = function () {
clearinterval(inter);
cleartimeout(rtnst);
cleartimeout(titst);
cleartimeout(pnst);
//cleartimeout(resizest);
};
//销毁事件绑定
this.destroyevents = function () {
nextbtn.off();
prevbtn.off();
conbox.off();
slider.off();
navobj.off();
//$(win).off();
};
//销毁插件
this.destroy = function () {
this.destroyevents();
this.destroyinter();
this.clearstyle();
};
//刷新
this.refresh = function () {
this.destroy();
setinit();
settrigger();
doplay(true);
setautoplay();
};
//重置(待完善)
this.reset = function () {
index = parseint(opts.defaultindex);
scroll = isnan(opts.scroll) ? "auto" : parseint(opts.scroll);
vis = isnan(opts.vis) ? "auto" : parseint(opts.vis);
autoplay = (opts.autoplay == "false" || opts.autoplay == false) ? false : true;
navobjsize = navobj.length;
conboxsize = conbox.children().length;
this.refresh();
};
//获取当前索引/页码
this.getindex = function () { return index };
//获取总页数
this.getpages = function () { return navobjsize };
//暂停
this.pause = function () { pausestatefun() };
this.play = function () { playstatefun() };
this.prev = function () { prevfun() };
this.next = function () { nextfun() };
this.goto = function (i) {
resetinter();
if (pnloop || i != navobjsize) {
index = i;
doplay();
}
};
}; //createobj end
this.each(function () {
var o = new createobj($.extend({}, $.fn.slide.defaults, options), $(this));
ary.push(o);
}); //each end
return ary;
}; //slide end
})(jquery, window);
jquery.easing['jswing'] = jquery.easing['swing'];
jquery.extend(jquery.easing,
{
def: 'easeoutquad',
swing: function (x, t, b, c, d) { return jquery.easing[jquery.easing.def](x, t, b, c, d); },
easeinquad: function (x, t, b, c, d) { return c * (t /= d) * t + b; },
easeoutquad: function (x, t, b, c, d) { return -c * (t /= d) * (t - 2) + b },
easeinoutquad: function (x, t, b, c, d) {
if ((t /= d / 2) < 1) {
return c / 2 * t * t + b;
}
return -c / 2 * ((--t) * (t - 2) - 1) + b;
},
easeincubic: function (x, t, b, c, d) { return c * (t /= d) * t * t + b },
easeoutcubic: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b },
easeinoutcubic: function (x, t, b, c, d) {
if ((t /= d / 2) < 1) {
return c / 2 * t * t * t + b;
}
return c / 2 * ((t -= 2) * t * t + 2) + b;
},
easeinquart: function (x, t, b, c, d) { return c * (t /= d) * t * t * t + b },
easeoutquart: function (x, t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b },
easeinoutquart: function (x, t, b, c, d) {
if ((t /= d / 2) < 1) {
return c / 2 * t * t * t * t + b;
}
return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
},
easeinquint: function (x, t, b, c, d) { return c * (t /= d) * t * t * t * t + b },
easeoutquint: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b },
easeinoutquint: function (x, t, b, c, d) {
if ((t /= d / 2) < 1) {
return c / 2 * t * t * t * t * t + b;
}
return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
},
easeinsine: function (x, t, b, c, d) { return -c * math.cos(t / d * (math.pi / 2)) + c + b },
easeoutsine: function (x, t, b, c, d) { return c * math.sin(t / d * (math.pi / 2)) + b },
easeinoutsine: function (x, t, b, c, d) { return -c / 2 * (math.cos(math.pi * t / d) - 1) + b },
easeinexpo: function (x, t, b, c, d) { return (t == 0) ? b : c * math.pow(2, 10 * (t / d - 1)) + b },
easeoutexpo: function (x, t, b, c, d) { return (t == d) ? b + c : c * (-math.pow(2, -10 * t / d) + 1) + b },
easeinoutexpo: function (x, t, b, c, d) {
if (t == 0) {
return b;
}
if (t == d) {
return b + c;
}
if ((t /= d / 2) < 1) {
return c / 2 * math.pow(2, 10 * (t - 1)) + b;
}
return c / 2 * (-math.pow(2, -10 * --t) + 2) + b;
},
easeincirc: function (x, t, b, c, d) { return -c * (math.sqrt(1 - (t /= d) * t) - 1) + b },
easeoutcirc: function (x, t, b, c, d) { return c * math.sqrt(1 - (t = t / d - 1) * t) + b },
easeinoutcirc: function (x, t, b, c, d) {
if ((t /= d / 2) < 1) {
return -c / 2 * (math.sqrt(1 - t * t) - 1) + b;
}
return c / 2 * (math.sqrt(1 - (t -= 2) * t) + 1) + b;
},
easeinelastic: function (x, t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) {
return b;
}
if ((t /= d) == 1) {
return b + c;
}
if (!p) {
p = d * .3;
}
if (a < math.abs(c)) {
a = c;
var s = p / 4;
} else {
var s = p / (2 * math.pi) * math.asin(c / a);
}
return -(a * math.pow(2, 10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p)) + b;
},
easeoutelastic: function (x, t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) {
return b;
}
if ((t /= d) == 1) {
return b + c;
}
if (!p) {
p = d * .3;
}
if (a < math.abs(c)) {
a = c;
var s = p / 4;
} else {
var s = p / (2 * math.pi) * math.asin(c / a);
}
return a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b;
},
easeinoutelastic: function (x, t, b, c, d) {
var s = 1.70158;
var p = 0;
var a = c;
if (t == 0) {
return b;
}
if ((t /= d / 2) == 2) {
return b + c;
}
if (!p) {
p = d * (.3 * 1.5);
}
if (a < math.abs(c)) {
a = c;
var s = p / 4;
} else {
var s = p / (2 * math.pi) * math.asin(c / a);
}
if (t < 1) {
return -.5 * (a * math.pow(2, 10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p)) + b;
}
return a * math.pow(2, -10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p) * .5 + c + b;
},
easeinback: function (x, t, b, c, d, s) {
if (s == undefined) {
s = 1.70158;
}
return c * (t /= d) * t * ((s + 1) * t - s) + b;
},
easeoutback: function (x, t, b, c, d, s) {
if (s == undefined) {
s = 1.70158;
}
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
},
easeinoutback: function (x, t, b, c, d, s) {
if (s == undefined) {
s = 1.70158;
}
if ((t /= d / 2) < 1) {
return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
}
return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
},
easeinbounce: function (x, t, b, c, d) { return c - jquery.easing.easeoutbounce(x, d - t, 0, c, d) + b },
easeoutbounce: function (x, t, b, c, d) {
if ((t /= d) < (1 / 2.75)) {
return c * (7.5625 * t * t) + b;
} else if (t < (2 / 2.75)) {
return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
} else if (t < (2.5 / 2.75)) {
return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
} else {
return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
}
},
easeinoutbounce: function (x, t, b, c, d) {
if (t < d / 2) {
return jquery.easing.easeinbounce(x, t * 2, 0, c, d) * .5 + b;
}
return jquery.easing.easeoutbounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
}
});