www.gusucode.com > 自适应宽度的jquery幻灯切换代码源码程序 > 自适应宽度的jquery幻灯切换代码/win8风格左右全屏大图焦点图幻灯片切换样式/win8风格左右全屏大图焦点图幻灯片切换样式/js/slides.js
// 代码提供:www.srcfans.com (function($) { $.extend($.browser, { client: function() { return { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight, bodyWidth: document.body.clientWidth, bodyHeight: document.body.clientHeight } }, scroll: function() { return { width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight, bodyWidth: document.body.scrollWidth, bodyHeight: document.body.scrollHeight, left: document.documentElement.scrollLeft + document.body.scrollLeft, top: document.documentElement.scrollTop + document.body.scrollTop } }, screen: function() { return { width: window.screen.width, height: window.screen.height } }, isIE6: $.browser.msie && $.browser.version == 6, isMinW: function(val) { return Math.min($.browser.client().bodyWidth, $.browser.client().width) <= val }, isMinH: function(val) { return $.browser.client().height <= val } }) }) (jQuery); (function(a) { a.fn.jdSlide = function(k) { var p = a.extend({ width: null, height: null, pics: [], index: 0, type: "num", current: "curr", delay1: 100, delay2: 5000 }, k || {}); var i = this; var g, f, d, h = 0, e = true, b = true; var n = p.pics.length; var o = function() { var q = "<ul style='position:absolute;top:0;left:0;'><li><a href='" + p.pics[0].href + "' target='_blank'><img src='" + p.pics[0].src + "' width='" + p.width + "' height='" + p.height + "' /></a></li></ul>"; i.css({ position: "relative" }).html(q); i.find("ul").css({ width: n * p.width + "px", height: p.height + "px" }); a(function() { c() }) }; o(); var j = function() { var s = []; s.push("<div>"); var r; var q; for (var t = 0; t < n; t++) { r = (t == p.index) ? p.current: ""; switch (p.type) { case "num": q = t + 1; break; case "string": q = p.pics[t].alt; break; case "image": q = "<img src='" + p.pics[t].breviary + "' />"; default: break } s.push("<span class='"); s.push(r); s.push("'><a href='"); s.push(p.pics[t].href); s.push("' target='_blank'>"); s.push(q); s.push("</a></span>") } s.push("</div>"); i.append(s.join("")); var x = []; x.push("<div id='goback' class='o-control'><a class='control'></a></div><div id='forward' class='o-control'><a class='control'></a></div>"); i.append(x.join("")); i.find("#goback").bind("mouseover", function() { b = false; clearTimeout(g); clearTimeout(d) }).bind("click", function() { var u = p.index - 1; if (u < 0) { u = t - 1 }; l(u) }).bind("mouseleave", function() { b = true; }); i.find("#forward").bind("mouseover", function() { b = false; clearTimeout(g); clearTimeout(d) }).bind("click", function() { var u = p.index + 1; l(u) }).bind("mouseleave", function() { b = true; }); i.find("span").bind("mouseover", function() { b = false; clearTimeout(g); clearTimeout(d); var u = i.find("span").index(this); if (p.index == u) { return } else { d = setInterval(function() { if (e) { l(u) } }, p.delay1) } }).bind("mouseleave", function() { b = true; clearTimeout(g); clearTimeout(d); g = setTimeout(function() { l(p.index + 1, true) }, p.delay2) }); i.bind("mouseover", function() { $("#ebaduslide .o-control").show() }).bind("mouseleave", function() { $("#ebaduslide .o-control").hide() }) }; var l = function(r, q) { if (r == n) { r = 0 } f = setTimeout(function() { i.find("span").eq(p.index).removeClass(p.current); i.find("span").eq(r).addClass(p.current); m(r, q) }, 20) }; var m = function(u, q) { var s = parseInt(h); var v = Math.abs(s + p.index * p.width); var t = Math.abs(u - p.index) * p.width; var r = Math.ceil((t - v) / 4); if (v == t) { clearTimeout(f); if (q) { p.index++; if (p.index == n) { p.index = 0 } } else { p.index = u } e = true; if (e && b) { clearTimeout(g); g = setTimeout(function() { l(p.index + 1, true) }, p.delay2) } } else { if (p.index < u) { h = s - r; i.find("ul").css({ left: h + "px" }) } else { h = s + r; i.find("ul").css({ left: h + "px" }) } e = false; f = setTimeout(function() { m(u, q) }, 20) } }; var c = function() { var q = []; for (var r = 1; r < n; r++) { q.push("<li><a href='"); q.push(p.pics[r].href); q.push("' target='_blank'><img src='"); q.push(p.pics[r].src); q.push("' width='"); q.push(p.width); q.push("' height='"); q.push(p.height); q.push("' /></a></li>") } i.find("ul").append(q.join("")); g = setTimeout(function() { l(p.index + 1, true) } , p.delay2); if (p.type) { j() } } } })(jQuery); //jQuery(function ($) { // if ( jQuery.browser.msie && ( jQuery.browser.version == "6.0" ) && !jQuery.support.style ){ // jQuery('div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td,hr,button,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section').hover(function(){ // jQuery(this).addClass('hover'); // },function(){ // jQuery(this).removeClass('hover'); // }); // } //}); $(document).ready(function() { var totWidth = 0; var positions = new Array(); var pwidth = $("#gallery").width(); $("#downloadwrap").css('visibility', 'hidden'); $(".slide").width(pwidth); $('#slides .slide').each(function(i) { positions[i] = totWidth; var f = pwidth - 980; totWidth += (980 + f); if (!$(this).width()) { return false; } }); $(window).resize(function() { totWidth = 0; positions = new Array(); pwidth = $("#gallery").width(); $(".slide").width(pwidth); $('#slides .slide').each(function(i) { positions[i] = totWidth; var f = pwidth - 980; totWidth += (980 + f); if (!$(this).width()) { return false; } }); $('#slides').width(totWidth).stop().animate({ marginLeft: -positions[0] + 'px' }, 0); }); $('#slides').width(totWidth); var timer = null; function onSecondDelay(callback) { clearTimeout(timer); timer = setTimeout(callback, 500); } $('.switch ul li').mouseover(function() { var _this = $(this); onSecondDelay(function() { _this.find('div').trigger('hover', [true]) }); }).mousemove(function() { var _this = $(this); onSecondDelay(function() { _this.find('div').trigger('hover', [true]) }); }).mouseout(function() { clearTimeout(timer); }); $('.switch ul li div').mouseover(function(e, keepScroll) { $('li.menuItem').removeClass('currbdbanner'); //$(this).parent().addClass('currbdbanner'); var li_id = $(this).parent().attr('id'); var li_id_num = li_id.split('_')[2]; $("#t_li_" + li_id_num).addClass('currbdbanner'); //$("#b_li_"+li_id_num).addClass('currbdbanner'); if ("1" == li_id_num || "4" == li_id_num) { $("#downloadwrap").css('visibility', 'hidden'); if ("1" == li_id_num) { $("#special2").show(); $("#special").hide(); } if ("4" == li_id_num) { $("#special2").hide(); $("#special").show(); } } else { $("#downloadwrap").css('visibility', ''); $("#special").hide(); $("#special2").hide(); } var pos = $(this).parent().prevAll('.menuItem').length; $('#slides').stop().animate({ marginLeft: -positions[pos] + 'px' }, 450); e.preventDefault(); if (!keepScroll) clearInterval(itvl); }); $('.switch ul li.menuItem:first').addClass('currbdbanner'); var current = 1; function autoAdvance() { if (current == -1) return false; $('.switch ul li div').eq(current % $('.switch ul li a').length).trigger('click', [true]); current++; } var changeEvery = 7; var itvl = setInterval(function() { autoAdvance() }, changeEvery * 600); }); $(document).ready(function() { window.index = 0; var auto; $("div.images").scrollLeft(0); var slider = function(obj) { //滑动函数 if (obj) _slider = $(obj); $("div.images").find("img").each(function() { $(this).fadeOut(500); }); $(obj).fadeIn(500); }; window.active = function() { var liwidth = $("#storeimgs li").width(); $("#storeimgs li").removeClass("slidehover"); $($("#storeimgs li").get(index)).addClass("slidehover"); $("#storeimgs li .jt").css({ "display": "none" }); $($("#storeimgs li .jt").get(index)).css({ "display": "block" }); slider("#images" + index); //切换图片 }; window.set = function() { //自动切换 auto = setInterval(function() { index = (++index) % $("#storeimgs li").length; active(); }, 10000000); }; window.clear = function() { //清楚自动切换 clearInterval(auto); }; /***************************update end***********************/ $("#storeimgs li").hover(function() { window.index = $("#storeimgs li").index(this); clear(); active(); set(); }, function() {}); /* $("#storeimgs li").mouseout(function(){ window.index=$("#storeimgs li").index(this); set(); }); */ /***************************update end***********************/ if ($("#storeimgs li").length > 1) { set(); } }); // 整站切换tab function setTab(name, cursel, n) { for (i = 1; i <= n; i++) { var menu = document.getElementById(name + i); var con = document.getElementById("news_" + name + "_" + i); menu.className = i == cursel ? "hover": ""; con.style.display = i == cursel ? "block": "none"; } }