/*javascript document*/ ; (function ($, window) { $.fn.addbannerscreen = function (options) { //鍚堝苟浼犲叆涓庨粯璁ょ殑鍙傛暟 var opts = $.extend({}, $.fn.addbannerscreen.defaultopts, options || {}); //瀹炵幇鏂规硶 $(this).each(function () { //瀵艰埅鑺傜偣鍒楄〃 鍐呭鑺傜偣鍒楄〃 var $that = $(this); var conbox = $(this).find("ul:first-child"); //婊氬姩瀹瑰櫒鐨勭埗鍏冪礌 var navlist = $(this).children('ul:last-child').children('li'); //瀵艰埅鑺傜偣鍒楄〃 var conlist = $(this).children('ul:first-child').children('li'); //鍐呭鑺傜偣鍒楄〃 var $prev = opts.handleprev != null ? $(this).find(opts.handleprev) : opts.handleprev; var $next = opts.handlenext != null ? $(this).find(opts.handlenext) : opts.handlenext; //褰撳墠绱㈠紩 涔嬪墠鐨勭储寮? 瀹氭椂鍣? 鏁堟灉寮曠敤鍑芥暟 var curindex = oldindex = opts.index; var timer = null,effectfn = null; //鏄惁姝e湪绉诲姩 瀵艰埅鑺傜偣鎬讳釜鏁? 鍐呭鑺傜偣姣忎竴涓搴?鎴栬€呴珮搴? var ismoving = false; var size = navlist.length; // 鍒ゆ柇鏄惁鏄瀭鐩存柟鍚? var itemsize = opts.isvertical ? math.ceil(conlist.eq(0).innerheight()) : math.ceil(conlist.eq(0).innerwidth()); // 娴忚鍣ㄤ簨浠? if (opts.isfullscreen) { // 姘村钩鏂瑰悜鎵嶉渶瑕佹墽琛屼笅闈㈢殑浜嬩欢 if (!opts.isvertical) { $(window).bind("resize", function () { switch (opts.effect) { case "twin": itemsize = $(window).width(); conlist.css({ 'left' : itemsize, 'width' : itemsize }).eq(curindex).css('left', 0); conbox.css({ "width" : itemsize }); break; case "order": itemsize = $(window).width(); conlist.width(itemsize); conbox.css({ "width" : itemsize * size }); if (ismoving) { conbox.stop(true, true); effectfn(); } else { effectfn(); }; break; default: return; }; }); }else { // 璺宠繃 }; }; // 涓婁竴寮? $prev != null ? $prev.bind("click", function () { switch (opts.effect) { case "twin": var newindex = ((curindex) - 1 < 0) ? size - 1 : curindex - 1; if (ismoving || conlist.is(":animated")) { return; } //璧嬪€兼棫鐨勭储寮?鏂扮殑绱㈠紩 oldindex = curindex; curindex = newindex; // 璁剧疆瀵艰埅鐨勫綋鍓嶈妭鐐? setclass(curindex); // 鎵ц鍑芥暟 涓€鐩存湞涓? changetwinprevious(); break; default: var newindex = ((curindex) - 1 < 0) ? size - 1 : curindex - 1; navlist.eq(newindex).trigger(opts.mousetype); return; }; }) : ""; // 涓嬩竴寮? $next != null ? $next.bind("click", function () { switch (opts.effect) { case "twin": var newindex = ((curindex + 1) >= size) ? 0 : curindex + 1; if (ismoving || conlist.is(":animated")) { return; } //璧嬪€兼棫鐨勭储寮?鏂扮殑绱㈠紩 oldindex = curindex; curindex = newindex; // 璁剧疆瀵艰埅鐨勫綋鍓嶈妭鐐? setclass(curindex); // 鎵ц鍑芥暟 涓€鐩存湞涓? changetwinnext(); break; default: //璧嬪€兼棫鐨勭储寮?鏂扮殑绱㈠紩 var newindex = ((curindex + 1) >= size) ? 0 : curindex + 1; navlist.eq(newindex).trigger(opts.mousetype); return; }; }) : ""; //閬嶅巻瀵艰埅鑺傜偣鍒楄〃 navlist.each(function (i) { //鑺傜偣绱㈠紩 var index = i; //缁戝畾浜嬩欢 $(this).bind(opts.mousetype, function (e) { //鍒ゆ柇鏄惁鏄綋鍓嶇储寮?濡傛灉鏄洿鎺ヨ繑鍥? if (index == curindex) { return; } //鏄惁姝e湪缂撳姩 濡傛灉鏄洿鎺ヨ繑鍥? if (ismoving || conbox.is(":animated")) { return; } //璧嬪€兼棫鐨勭储寮?鏂扮殑绱㈠紩 oldindex = curindex; curindex = index; // 璁剧疆瀵艰埅鐨勫綋鍓嶈妭鐐? setclass(curindex); //杩愯鎵ц鏁堟灉鏂规硶 閲嶇疆瀹氭椂鍣? 闃绘榛樿琛屼负 effectfn(); autotimer(); e.preventdefault(); }); }); // 璁剧疆瀵艰埅 class鍑芥暟 function setclass(index) { var $that = navlist.eq(index); //娣诲姞鏍峰紡 绉婚櫎鏍峰紡 if (opts.classtype == 'only') { $that.addclass(opts.selectedclass).siblings().removeclass(opts.selectedclass); } else { $that.addclass(opts.selectedclass + string(curindex + 1)).siblings().removeclass((opts.selectedclass + string(oldindex + 1))); } } //瀹氭椂鍣? function autotimer() { if (!opts.autoplay) { return; } if (timer) { clearinterval(timer); } timer = setinterval(autoplay, opts.delay); } //鏆傚仠鎾斁 function stoptimer() { clearinterval(timer); } //鑷姩鎾斁 function autoplay() { // var newindex = ((curindex + 1) >= size) ? 0 : curindex + 1; // navlist.eq(newindex).trigger(opts.mousetype) var newindex = ((curindex + 1) >= size) ? 0 : curindex + 1; if (ismoving || conlist.is(":animated")) { return; } //璧嬪€兼棫鐨勭储寮?鏂扮殑绱㈠紩 oldindex = curindex; curindex = newindex; // 璁剧疆瀵艰埅鐨勫綋鍓嶈妭鐐? setclass(curindex); // 鎵ц鍑芥暟 涓€鐩存湞涓? changetwinnext(); } //鍒濆鍖栧鑸妭鐐规牱寮? navlist.eq(curindex).addclass((opts.classtype == 'only') ? opts.selectedclass : opts.selectedclass + string(curindex + 1)); //璁剧疆鍐呭鑺傜偣鏍峰紡 鏁堟灉鍑芥暟 switch (opts.effect) { case "fade": conlist.css({ 'position' : 'absolute', 'left' : 0, 'top' : 0 }).hide().eq(curindex).show(); effectfn = changefade; break; case "twin": if (opts.isvertical) { // 鍨傜洿鏂瑰悜璋冪敤鐨勫嚱鏁? conlist.css({ 'position' : 'absolute', 'top' : 0, 'top' : itemsize, 'height' : itemsize }).eq(curindex).css('top', 0); effectfn = changetwinv; } else { // 姘村钩鏂瑰悜璋冪敤鐨勫嚱鏁? conlist.css({ 'position' : 'absolute', 'top' : 0, 'left' : itemsize, 'width' : itemsize }).eq(curindex).css('left', 0); effectfn = changetwinh; } break; case "order": if (opts.isvertical) { // 鍨傜洿鏂瑰悜璋冪敤鐨勫嚱鏁? conbox.css({ 'position' : 'relative', 'height' : size * itemsize }); effectfn = changeorderv; } else { // 姘村钩鏂瑰悜璋冪敤鐨勫嚱鏁? conbox.css({ 'position' : 'relative', 'width' : size * itemsize }); conlist.css("float", "left"); effectfn = changeorderh; } break; case "back": effectfn = changecallback; break; } //娓愰殣鍒囨崲 function changefade() { conlist.eq(curindex).css({ "z-index" : "999" }).stop(true, true).fadein(opts.tweentime, opts.ease) .siblings().css("z-index", "0").fadeout(opts.tweentime + 200, opts.ease); opts.itemhandler != null ? changecallback(curindex) : ""; } //涓嶉棿鏂簭鍒楀垏鎹㈡按骞虫柟鍚? function changetwinh() { ismoving = true; var pos = (curindex > oldindex) ? itemsize : -itemsize; conlist.eq(curindex).css('left', pos).animate({ "left" : 0 }, opts.tweentime) .end().eq(oldindex).animate({ "left" : -pos }, opts.tweentime, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; } //涓嶉棿鏂簭鍒楀垏鎹㈠瀭鐩存柟鍚? function changetwinv() { ismoving = true; var pos = (curindex > oldindex) ? itemsize : -itemsize; conlist.eq(curindex).css('top', pos).animate({ "top" : 0 }, opts.tweentime) .end().eq(oldindex).animate({ "top" : -pos }, opts.tweentime, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; } //涓嶉棿鏂簭鍒楀垏鎹竴鐩存湞鍓嶉潰涓€寮? function changetwinprevious() { ismoving = true; if (!opts.isvertical) { // 姘村钩鏂瑰悜 var pos = -itemsize //(curindex > oldindex) ? itemsize : -itemsize; conlist.eq(curindex).css('left', pos).animate({ "left" : 0 }, opts.tweentime) .end().eq(oldindex).animate({ "left" : -pos }, opts.tweentime, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; } else { // 鍨傜洿鏂瑰悜 var pos = -itemsize //(curindex > oldindex) ? itemsize : -itemsize; conlist.eq(curindex).css('top', pos).animate({ "top" : 0 }, opts.tweentime) .end().eq(oldindex).animate({ "top" : -pos }, opts.tweentime, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; }; }; //涓嶉棿鏂簭鍒楀垏鎹竴鐩存湞鍚庨潰涓€寮? function changetwinnext() { if (!opts.isvertical) { // 姘村钩鏂瑰悜 ismoving = true; var pos = itemsize //(curindex > oldindex) ? itemsize : -itemsize; conlist.eq(curindex).css('left', pos).animate({ "left" : 0 }, opts.tweentime) .end().eq(oldindex).animate({ "left" : -pos }, opts.tweentime, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; } else { // 鍨傜洿鏂瑰悜 ismoving = true; var pos = itemsize //(curindex > oldindex) ? itemsize : -itemsize; conlist.eq(curindex).css('top', pos).animate({ "top" : 0 }, opts.tweentime) .end().eq(oldindex).animate({ "top" : -pos }, opts.tweentime, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; }; }; //搴忓垪鍒囨崲鍨傜洿鏂瑰悜 function changeorderv() { ismoving = true; conbox.stop(true, true).animate({ 'top' : -curindex * itemsize }, opts.tweentime, opts.ease, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; } //搴忓垪鍒囨崲姘村钩鏂瑰悜 function changeorderh() { ismoving = true; conbox.stop(true, true).animate({ 'left' : -curindex * itemsize }, opts.tweentime, opts.ease, function () { ismoving = false; }); opts.itemhandler != null ? changecallback(curindex) : ""; } //鐩存帴璋冪敤鍥炶皟鍑芥暟杩斿洖 浼犲叆褰撳墠绱㈠紩 function changecallback() { if (opts.itemhandler != null) { opts.itemhandler(curindex); } } //杩愯瀹氭椂鍣? autotimer(); $(this).hover(function () { stoptimer(); }, function () { autotimer(); }).trigger("mouseout"); }); } /* * 榛樿鍙傛暟 * effect 璁剧疆閭g鏁堟灉(fade twin order)(榛樿娓愰殣fade) * index 榛樿绱㈠紩 * selectedclass 瀵艰埅鑺傜偣閫変腑鏍峰紡 * classtype 鏍峰紡绫诲瀷鍗曚釜(only)澶氫釜(muilt) (榛樿鍗曚釜only) * mousetype 浜嬩欢绫诲瀷 * tweentime 缂撳姩鏃堕棿 * handleprev 鍓嶄竴寮? * handlenext 鍚庝竴寮? * delay 鑷姩鎾斁绛夊緟鏃堕棿(榛樿6000---6绉? * autoplay 鏄惁鑷姩鎾斁 * isvertical 鏄惁鏄瀭鐩存柟鍚? * ease 缂撳姩鍑芥暟(璁$畻鍑芥暟) swing linear */ $.fn.addbannerscreen.defaultopts = { effect : "order", index : 0, selectedclass : "on", classtype : "only", mousetype : "click", tweentime : 600, delay : 6000, autoplay : false, handleprev : null, handlenext : null, ease : "swing", isvertical : false, isfullscreen : false, itemhandler : null }; })(jquery, window);