$(document).ready(function () { $(".indexdiv3c").duzhan_hotnew({ showclass: ".indexdiv3c", show_leg: "1"}); }); (function ($) { $.fn.duzhan_hotnew = function (options) { var defaults = { showclass: "huo_jjfa_div", showspanindex: "", showtime: "6000", show_leg: "1" }; var showindex = 0; var options = $.extend(defaults, options); var showlist = $(options.showclass + " dl"); var showfirst = showlist.eq(0); options.show_leg = 1; //var len = parseint(showlist.length % options.show_leg > 0 ? showlist.length / options.show_leg + 1 : showlist.length / options.show_leg); var len = $(options.showclass + " dl").length - options.show_leg+1; //alert(len); var index = 0; var showcur = "cur"; var shownowclass = options.showclass; var pictimer; // showlist.css({ "width": showlist.width(), "margin": showlist.css("margin") }) showlist.css({ "width": showlist.width()+2, "margin": showlist.css("margin") }) if($(window).width() <= 1024){ showlist.css({ "width": showlist.width()+1, "margin": showlist.css("margin") }) } // $(shownowclass).height(showfirst.height() + 10); // $(shownowclass + " .huo_jjfa_list").css({ "width": showfirst.outerwidth(true) * showlist.length+100, "height": showfirst.height() + 10, "position": "absolute" }); $(shownowclass + " .indexdiv3clist").css({ "width": showfirst.outerwidth(true) * showlist.length+100, "position": "absolute" }); var swidth = showfirst.outerwidth(true) * options.show_leg; var movewidth = $(options.showclass + " dl ").outerwidth(true); // if (len > 1) { // for (var i = 0; i < len; i++) { // $(options.showspanindex).append(""); // } // } // $(".prev").live("click", function () { $(".njtl").click(function(){ clearinterval(pictimer); if (index > 0) { index--; showmove(); }else{ index=len-1; showmove(); } }); // $(".next").live("click", function () { $(".njtr").click(function(){ clearinterval(pictimer); if (index < len - 1) { index++; showmove(); }else{ index=0; showmove(); } }); // //手机版 var rx = 0, tx = 0, ty_end = 0, ismoved = false; $(document).delegate(options.showclass, "touchstart", function (e) { //e.preventdefault(); if (!event.touches.length) return; var touch = event.touches[0]; rx = parseint(this.style.left || 0); tx = ty_end = touch.pagex; }); $(document).delegate(options.showclass, "touchmove", function (e) { //e.preventdefault(); if (!event.touches.length) return; var touch = event.touches[0]; ty_end = touch.pagex; var x = touch.pagex - tx + rx; if (x <= -(len - 1) * swidth || x >= 0) { return; } //$(options.showclass + " .indexjxdivlist").css("transform", "translatex(" + x + "px)"); }); $(document).delegate(options.showclass, "touchend", function (event) { if (ty_end > tx + 25) { if (index > 0) { index--; showmove(index) } } else if (ty_end < tx - 25) { if (index < len - 1) { index++; showmove(index) } } }); //结束 // pictimer = setinterval(automove, options.showtime); function automove() { index++; if (index >= len) { index = 0; } showmove(index); } function showmove() { if (index < len) { // clearinterval(pictimer); var nowleft = -index * movewidth; $(options.showclass + " .indexdiv3clist").stop(true, false).animate({ "left": nowleft }, 500, function () { }); // $(options.showspanindex + " span").removeclass(showcur).eq(index).addclass(showcur); } else { // showfirpic(); index = 0; } } } })(jquery)