我已经创建了自定义滑块,但它不起作用,请各位大神指导一下。
我的代码:
var mwth = 0;
var count = 0;
var wth = 0;
var twth = 0;
$(document).ready(function () {
$('.box-wrap .box:odd').css("background", "#0C0");
mwth = $('.box-wrap').width();
count = $('.box-wrap .box').size();
wth = $('.box-wrap .box').width();
twth = (count) * (wth + 2)
$('.box-wrap .box').wrapAll("<div class='slider-wp'>");
$(".slider-wp").css("width", twth);
for (i = 0; i < (twth / mwth); i++) {
$(".box-wrap").append("<a href='#'>test</a>")
}
$(".box-wrap a").each(function (index, element) {
$(this).click(function () {
banner_slide((index) * 990);
return;
});
});
setInterval(banner_slider, 1000);
});
function banner_slide(i) {
$(".slider-wp").animate({
left: "-" + i + ""
}, 1000).delay(1000);
}
function banner_slider(cnt) {
twth = (count) * (wth + 2)
var j = 1000;
for (i = 0; i <= (twth - 990); i = i + 990) {
j = j + 1000;
$(".slider-wp").animate({
left: "-" + i + ""
}, 1000).delay(j);
}
}