(function ($) {
$.fn.slide1 = function (options) {
var dft = {
zs_lunlock: true,
autoplay: true,
autotime: 4000,
curentimg: 0,
height: 0,
clickluntime: 500
};
var ops = $.extend(dft, options);
var zs_item = $(this).find(".slideitem");
var zs_itemwidth = $(this).find(".slideitem").width();
var t_time;
var isimgload = false;
var $this = this;
var zs_dotlisthtml = "
";
var zs_dots;
var maxheight = 0;
var checkvideo = 0;
if (ops.height == 0) {
t_time = setinterval(function () {
$($this).find(".slideitem img").each(function () {
if (this.height === 0 && $(this).is(":visible")) {
isimgload = false;
return false;
} else {
maxheight = maxheight > $(this).height() ? maxheight : $(this).height();
isimgload = true;
}
});
if (isimgload) {
maxheight = maxheight > $($this).height() ? maxheight : $($this).height();
clearinterval(t_time);
if ($($this).find(".slideitem").find("video").length > 0 && checkvideo == 0) {
checkvideo = 1;
}
if (checkvideo > 0) {
$($this).find(".carouse").height(maxheight - 5);
} else {
$($this).find(".carouse").height(maxheight);
}
$($this).find(".playbtn").css("top", (maxheight - 50) / 2);
lunbo();
}
//itemimgload(callback); // 閫掑綊鎵弿
//console.log();
}, 100); // 鎴戣繖閲岃缃殑鏄�100姣灏辨壂鎻忎竴娆★紝鍙互鑷繁璋冩暣
}
function lunbo() {
zs_itemwidth = $($this).find(".slideitem").width();
if (ops.height == 0) {
if (checkvideo > 0) {
$($this).find(".carouse").height($($this).find(".slideitem").height() - 5);
} else {
$($this).find(".carouse").height($($this).find(".slideitem").height());
}
$($this).find(".playbtn").css("top", ($($this).find(".slideitem").height() - 50) / 2);
} else {
$($this).find(".carouse").height(ops.height);
}
for (var i = 0; i < zs_item.length; i++) {
$($this).find(".itemindex" + i).css("left", zs_itemwidth * i);
}
}
$(window).resize(function () {
lunbo();
});
for (var i = 0; i < zs_item.length; i++) {
var toleft = zs_itemwidth * i;
$(this).find(zs_item[i]).css("left", toleft);
$(this).find(zs_item[i]).addclass("itemindex" + i);
zs_dotlisthtml += '';
if (i == zs_item.length - 1) {
zs_dotlisthtml += "
";
var zs_showword = "";
$(this).find(".dotlist").html(zs_dotlisthtml);
$(this).find(".arti-content").html(zs_showword);
$(this).find('.dotlist ul li').first().addclass("active");
$($this).find(".arti-content .showlunword").html($($this).find(zs_item[0]).find(".slidedetail").html());
zs_dots = $(this).find('.dot');
}
}
var zs_next = function () {
lunbo();
if (ops.zs_lunlock) {
ops.zs_lunlock = false;
var move_left = 0;
var intemcount = zs_item.length - 1;
$($this).find(".itemindex" + intemcount).css("left", -zs_itemwidth);
for (var i = 0; i < zs_item.length; i++) {
move_left = parsefloat($($this).find(".itemindex" + i).css("left")) + parsefloat($($this).find(".slideitem").width());
$($this).find(".itemindex" + i).animate({ left: move_left }, 500);
}
for (var j = 0; j < zs_item.length; j++) {
var classname = $($this).find(zs_item[j]).attr("class") + "";
var count = classname.indexof("itemindex");
var index = classname.substring(count, classname.length);
var pp = index.indexof(" ");
if (pp > 0) {
index = index.substring(9, pp);
} else {
index = index.substring(9, index.length);
}
$($this).find(zs_item[j]).removeclass("itemindex" + index);
var next_index = parseint(index) + 1;
if (next_index == zs_item.length) {
next_index = 0;
}
//鎺у埗搴曢儴鍦嗙偣
$($this).find(zs_dots[j]).removeclass("active");
if (next_index == 0) {
$($this).find(zs_dots[j]).addclass("active");
$($this).find(".arti-content .showlunword").html($($this).find(zs_item[j]).find(".slidedetail").html());
}
$($this).find(zs_item[j]).addclass("itemindex" + next_index);
}
settimeout(function () {
ops.zs_lunlock = true;
}, 500);
}
};
var zs_pre = function () {
lunbo();
if (ops.zs_lunlock) {
ops.zs_lunlock = false;
var move_left = 0;
for (var i = 0; i < zs_item.length; i++) {
move_left = parsefloat($($this).find(".itemindex" + i).css("left")) - parsefloat($($this).find(".slideitem").width());
$($this).find(" .itemindex" + i).animate({ left: move_left }, 500);
}
for (var j = 0; j < zs_item.length; j++) {
var classname = $($this).find(zs_item[j]).attr("class") + "";
var count = classname.indexof("itemindex");
var index = classname.substring(count, classname.length);
var pp = index.indexof(" ");
if (pp > 0) {
index = index.substring(9, pp);
} else {
index = index.substring(9, index.length);
}
$($this).find(zs_item[j]).removeclass("itemindex" + index);
var next_index = parseint(index) - 1;
if (next_index == -1) {
next_index = zs_item.length - 1;
}
//鎺у埗搴曢儴鍦嗙偣
$($this).find(zs_dots[j]).removeclass("active");
if (next_index == 0) {
$($this).find(zs_dots[j]).addclass("active");
$($this).find(".arti-content .showlunword").html($($this).find(zs_item[j]).find(".slidedetail").html());
}
$($this).find(zs_item[j]).addclass("itemindex" + next_index);
}
settimeout(function () {
var des = parsefloat(zs_itemwidth) * (zs_item.length - 1);
$($this).find(".itemindex" + (zs_item.length - 1)).animate({ left: des }, 0.01);
ops.zs_lunlock = true;
}, 500);
}
}
$(this).find(".next").click(function () {
zs_next();
});
$(this).find(".previous").click(function () { zs_pre(); });
$(this).find(".dot").click(function () {
lunbo();
var dotintex = $(this).attr("dotindex");
var itemindex = "";
for (var i = 0; i < zs_item.length; i++) {
var tagclass = $($this).find(zs_item[i]).attr("class") + "";
if (tagclass.indexof("itemindex0") > 0) {
itemindex = i;
}
}
var dvalue = dotintex - itemindex;
if (dvalue > 0) {
zs_prevgo(dvalue);
} else {
zs_nextgo(-dvalue);
}
});
var zs_prevgo = function (dvalue) {
if (ops.zs_lunlock) {
ops.zs_lunlock = false;
var move_left = 0;
for (var i = 0; i < zs_item.length; i++) {
move_left = parsefloat($($this).find(".itemindex" + i).css("left")) - dvalue * parsefloat($($this).find(".slideitem").width());
$($this).find(" .itemindex" + i).animate({ left: move_left }, ops.clickluntime);
}
for (var j = 0; j < zs_item.length; j++) {
var classname = $($this).find(zs_item[j]).attr("class") + "";
var count = classname.indexof("itemindex");
var index = classname.substring(count, classname.length);
var pp = index.indexof(" ");
if (pp > 0) {
index = index.substring(9, pp);
} else {
index = index.substring(9, index.length);
}
$($this).find(zs_item[j]).removeclass("itemindex" + index);
var next_index = parseint(index) - dvalue;
if (next_index < 0) {
next_index = zs_item.length + next_index;
}
//鎺у埗搴曢儴鍦嗙偣
$($this).find(zs_dots[j]).removeclass("active");
if (next_index == 0) {
$($this).find(zs_dots[j]).addclass("active");
$($this).find(".arti-content .showlunword").html($($this).find(zs_item[j]).find(".slidedetail").html());
}
$($this).find(zs_item[j]).addclass("itemindex" + next_index);
}
settimeout(function () {
for (var m = 0; m < zs_item.length; m++) {
var des = parsefloat(zs_itemwidth) * (zs_item.length - 1 - m);
$($this).find(".itemindex" + (zs_item.length - 1 - m)).animate({ left: des }, 0.01);
}
ops.zs_lunlock = true;
}, 500);
}
}
var zs_nextgo = function (dvalue) {
if (ops.zs_lunlock) {
ops.zs_lunlock = false;
var move_left = 0;
var y = zs_item.length - 1;
for (var x = 0; x < dvalue; x++) {
$($this).find(".itemindex" + y).css("left", -zs_itemwidth - x * zs_itemwidth);
y--;
}
for (var i = 0; i < zs_item.length; i++) {
move_left = parsefloat($($this).find(".itemindex" + i).css("left")) + dvalue * parsefloat($($this).find(".slideitem").width());
$($this).find(" .itemindex" + i).animate({ left: move_left }, ops.clickluntime);
}
for (var j = 0; j < zs_item.length; j++) {
var classname = $($this).find(zs_item[j]).attr("class") + "";
var count = classname.indexof("itemindex");
var index = classname.substring(count, classname.length);
var pp = index.indexof(" ");
if (pp > 0) {
index = index.substring(9, pp);
} else {
index = index.substring(9, index.length);
}
$($this).find(zs_item[j]).removeclass("itemindex" + index);
var next_index = parseint(index) + dvalue;
if (next_index >= zs_item.length) {
next_index = next_index - zs_item.length;
}
//鎺у埗搴曢儴鍦嗙偣
$($this).find(zs_dots[j]).removeclass("active");
if (next_index == 0) {
$($this).find(zs_dots[j]).addclass("active");
$($this).find(".arti-content .showlunword").html($($this).find(zs_item[j]).find(".slidedetail").html());
}
$($this).find(zs_item[j]).addclass("itemindex" + next_index);
}
settimeout(function () {
ops.zs_lunlock = true;
}, 500);
}
};
$(this).bind('touchstart', function (e) {
startx = e.originalevent.changedtouches[0].pagex,
starty = e.originalevent.changedtouches[0].pagey;
});
$(this).bind('touchend', function (e) {
endx = e.originalevent.changedtouches[0].pagex,
endy = e.originalevent.changedtouches[0].pagey;
//鑾峰彇婊戝姩璺濈
distancex = endx - startx;
distancey = endy - starty;
//鍒ゆ柇婊戝姩鏂瑰悜
if (math.abs(distancex) > math.abs(distancey) && distancex > 0) {
zs_next();
} else if (math.abs(distancex) > math.abs(distancey) && distancex < 0) {
zs_pre();
}
});
var zs_luninterval = setinterval(function () {
if (ops.autoplay) {
zs_pre();
}
}, ops.autotime);
if (!ops.autoplay) {
clearinterval(zs_luninterval);
}
//榧犳爣婊戣繃鏆傚仠
zs_item.hover(function(){
ops.autoplay=false
},function(){
ops.autoplay=true
})
};
})(jquery);