//获取页面可见区域宽度、高度(不包含边框) function fnGetDocumentClient(){ return {width:top.document.documentElement.clientWidth||top.document.body.clientWidth,height:top.document.documentElement.clientHeight||top.document.body.clientHeight} } //获取页面正文区域宽度、高度 function fnGetDocumentScroll(){ return {width:top.document.documentElement.scrollWidth||top.document.body.scrollWidth,height:top.document.documentElement.scrollHeight||top.document.body.scrollHeight} } (function(){ y=window._={ onload:function(b){var c=window.onload;window.onload=typeof window.onload!="function"?b:function(){c();b()}}, scroll:function(o){ o=o||document.documentElement; return {w:o.scrollWidth,h:o.scrollHeight} }, client:function(o){ o=o||document.documentElement; return {w:o.clientWidth,h:o.clientHeight} }, init:function(e,b,d){b=b||{};d=d||{};for(var c in d)e[c]=b[c]||b[c]==0?b[c]:d[c]} }; })() var floatFrame=function(pJso){ _.init(this,pJso,{ src:"",//框架路径 param:"",//参数 width:0,//框架宽度 height:0,//框架高度 title:'提示信息', fnClose:this.hide//关闭时触发的函数 }); this.fullDiv=top.document.getElementById("cFunllDiv")||top.document.createElement("div"); this.frameDiv=top.document.getElementById("cFrameDiv")||top.document.createElement("div"); this.frame=null; this.frameName='cFrame'; this.set(); } floatFrame.prototype={ set:function(){ this.frame=top.frames[this.frameName]; if(!this.frame){ this.fullDiv.style.cssText="position:absolute;top:0px;left:0px;display:none;background-color:#000;filter:alpha(opacity=10);-moz-opacity:0.1;opacity: 0.1;z-index:9"; this.frameDiv.style.cssText="position:absolute;display:none;background-color:#fff;z-index:99999"; this.frameDiv.innerHTML= '
' +'
' +'
' +'
' +'
' +'' +'
' +'
' +'
'; this.fullDiv.setAttribute("id","cFunllDiv"); top.document.body.appendChild(this.fullDiv); this.frameDiv.setAttribute("id","cFrameDiv"); top.document.body.appendChild(this.frameDiv); this.frame=top.frames[this.frameName]; } }, hide:function(){ this.fullDiv.style.display="none"; this.frameDiv.style.display="none"; top.document.getElementById(this.frameName).src=""; }, show:function() { top.document.getElementById('float01-title').innerHTML= '
'+ '
'+ '
'+this.title+'
'+ '
'; top.document.getElementById("cClose").onclick=function(o){return function(){o.fnClose()}}(this); var iClientWidth=fnGetDocumentClient().width; var iClientHeight=fnGetDocumentClient().height; var iScrollWidth=fnGetDocumentScroll().width; var iScrollHeight=fnGetDocumentScroll().height; var iFullDivWidth=iScrollWidth; var iFullDivHeight=iScrollHeight>iClientHeight?iScrollHeight:iClientHeight with(this.fullDiv.style){ width=iFullDivWidth+"px" height=iFullDivHeight+"px"; display=""; } var iTop=(iClientHeight-this.height)*(1-0.818); var iLeft=(iClientWidth-this.width)*0.5; iTop=iTop>0?iTop:0; iLeft=iLeft>0?iLeft:0; var f=top.document.getElementById(this.frameName); var ttt=this; top.document.onkeydown=document.onkeydown=function(e){ e=e||top.event||event; if(e.keyCode==27) ttt.hide(); } if(this.frameDiv["attachEvent"]){ f.onreadystatechange=function(){ if(f.readyState === "complete"){ ttt.frame.document.onkeydown=function(){ if(ttt.frame.event.keyCode==27) ttt.hide(); } } } }else{ f.onload=function(){ ttt.frame.document.onkeydown=function(e){ if(e.keyCode==27) ttt.hide(); } } } var u=this.src+"?"+this.param; f.src=u; with(this.frameDiv.style){ display="block"; } } } var FloatFrame=function(){}; FloatFrame.autoLocal=function(){ var cFrame=top.document.getElementById('cFrame'); var cFloatDiv=top.document.getElementById('cFrameDiv'); var div_cFrame=top.document.getElementById('div_cFrame'); cFrame.style.width="1px"; cFrame.style.heght="1px"; var cur=_.scroll(); with(cFrame.style){ width=cur.w+'px'; height=cur.h+'px'; } var cli=_.client(top.document.documentElement); var iTop=(cli.h-cur.h)/2+(top.document.documentElement.scrollTop||top.document.body.scrollTop); var iLeft=(cli.w-cur.w)/2; iTop=iTop>0?iTop:0; iLeft=iLeft>0?iLeft:0; with(cFloatDiv.style){ top=iTop+"px"; left=iLeft+"px"; } var cur=_.scroll(); with(cFrame.style){ width=cur.w+'px'; height=cur.h+'px'; } with(div_cFrame.style){ width=(cur.w+30)+'px'; } }; var off; $(function(){ off=new floatFrame({title:'',src:''}); }); function alertFeedBack(id){ off.src='ajax/feedback.asp'; off.param='id='+id; off.show(); } function getCartCount(){ $.ajax({url:'ajax/get_cartcount.asp',type:'get',success:function(data){$('#cartCount').html(data);}}); } // 背景跟随鼠标 jQuery.fn.MouseDirection = function(opts){ opts = $.extend({}, { _label:'' },opts); var l = opts._label; var ds = l.size(); var d = l.find('.dir').size(); if( ds > 0 ) { if(d == 0){ l.append("
"); } l.css({'position':'relative','overflow':'hidden'}); l.find(".atm-img").css({'transform':'none'}); l.find(".dir").css({'width':'101%','height':'101%','position':'absolute','left':'-101.5%','top':'-0.5%','z-index':'2'}); } var dirs = ['top', 'right', 'bottom', 'left']; var calculate = function (l,e) { var x1,y1,x4,y4,x0,y0,k,rect=l.getBoundingClientRect(); if(!rect.width) { rect.width = rect.right - rect.left; } if(!rect.height) { rect.height = rect.bottom - rect.top; } x1 = rect.left; y1 = -rect.top; x4 = rect.left + rect.width; y4 = -(rect.top + rect.height); x0 = rect.left + rect.width / 2; y0 = -(rect.top + rect.height / 2); if (Math.abs(x1 - x4) < 0.0001) return 4; k = (y1 - y4) / (x1 - x4); var range=[k, -k],x,y,kk; x = e.clientX; y = -e.clientY; kk = (y - y0) / (x - x0); if(isFinite(kk) && range[0] < kk && kk < range[1]) { return x > x0 ? 1 : 3; } else { return y > y0 ? 0 : 2; } }; l.on('mouseenter', function (e) { var r = calculate(this, e); animationIn(l, dirs[r]); }).on('mouseleave', function (e) { var r = calculate(this, e); animationOut(l, dirs[r]); }); var DIR_POS = { left: { top: '-0.5%', left: '-101.5%' }, right: { top: '-0.5%', left: '100.5%' }, bottom: { top: '100.5%', left: '-0.5%' }, top: { top: '-101.5%', left: '-0.5%' } } function animationIn(l,dir) { var $bg = l.find(".dir").removeClass('trans'); $bg.css(DIR_POS[dir]); $bg[0].offsetWidth; $bg.addClass('trans'); $bg.css({left: '-0.5%', top: '-0.5%'}); } function animationOut(l,dir) { l.find(".dir").css(DIR_POS[dir]); } } // 图片垂直居中,等比例缩放 jQuery.fn.loadthumb = function(options) { options = $.extend({ _img:'', maxW:100, maxH:100, model:3 },options); var src=options._img.attr('src'); var p=options._img.attr('t'); var par=options._img.parent(); var _self = this; _self.hide(); var img = new Image(); $(img).load(function(){ imgDem = {}; imgDem.w = img.width; imgDem.h = img.height; if(p=='p1'){ imgDem = $.imgResize({"w": options.maxW ,"h": options.maxH},{"w":imgDem.w,"h":imgDem.h}); } if(p=='p2'){ imgDem = $.imgResizel({"w": options.maxW ,"h": options.maxH},{"w":imgDem.w,"h":imgDem.h}); } var imgMargins = $.imgCenter({"w": par.width() ,"h": par.height()},{"w":imgDem.w,"h":imgDem.h}); // options._img.css({width:imgDem.w,height:imgDem.h,marginLeft:imgMargins.l,marginTop:imgMargins.t}); if(options.model==1 || options.model==3) options._img.css({width:imgDem.w,height:imgDem.h}); if(options.model==2 || options.model==3) options._img.css({marginLeft:imgMargins.l,marginTop:imgMargins.t}); _self.attr("src", src); _self.fadeIn("slow"); }).attr("src", src); //.attr("src",options.src)要放在load后面, return _self; } // p1 重置图片宽高插件(parentDem是父元素,imgDem是图片) jQuery.imgResize = function(parentDem,imgDem){ if(imgDem.w>0 && imgDem.h>0){ var rate = (parentDem.w/imgDem.w < parentDem.h/imgDem.h)?parentDem.w/imgDem.w:parentDem.h/imgDem.h; //如果 指定高度/图片高度 小于 指定宽度/图片宽度,那么,我们的比例数 取 指定高度/图片高度。 //如果 指定高度/图片高度 大于 指定宽度/图片宽度,那么,我们的比例数 取 指定宽度/图片宽度。 if(rate <= 1){ imgDem.w = imgDem.w*rate; //图片新的宽度 = 宽度 * 比例数 imgDem.h = imgDem.h*rate; }else{ // 如果比例数大于1,则新的宽度等于以前的宽度。 imgDem.w = imgDem.w; imgDem.h = imgDem.h; } } return imgDem; } // p2 重置图片宽度,高度插件(parentDem是父元素,imgDem是图片) jQuery.imgResizel = function(parentDem,imgDem){ if(imgDem.w>0 && imgDem.h>0){ var ratw = parentDem.w/imgDem.w; var rath = parentDem.h/imgDem.h; var ratp = parentDem.w/parentDem.h; var ratm = imgDem.w/imgDem.h; if(ratp <= ratm){ imgDem.h = parentDem.h; imgDem.w = imgDem.w*rath; }else{ imgDem.w = parentDem.w; imgDem.h = imgDem.h*ratw; } } return imgDem; } // 使图片在父元素内水平/垂直居中(parentDem是父元素,imgDem是图片) jQuery.imgCenter = function(parentDem,imgDem){ var left = (parentDem.w - imgDem.w)*0.5; var top = (parentDem.h - imgDem.h)*0.5; return { "l": left , "t": top}; } // 动态描边 jQuery.fn.Runborder = function(obor){ obor = $.extend({}, { _border:'', _width:'', _color:'', _time:'' },obor); var border = obor._border; var bor = border.attr("bor"); var w = border.width(); var h = border.height(); var s = obor._width; var c = obor._color; var t = obor._time; border.append("
"); var bort = border.find(".bort"); var borr = border.find(".borr"); var borb = border.find(".borb"); var borl = border.find(".borl"); border.css({'position':'relative'}); border.find('.bor').css({'position':'absolute','z-index':10,'background-color': c}); bort.css({'width':0,'height':s,'left':0,'top':0}); borr.css({'width':s,'height':0,'right':0,'top':0}); borb.css({'width':0,'height':s,'right':0,'bottom':0}); borl.css({'width':s,'height':0,'left':0,'bottom':0}); if( bor == 't1' ){ border.hover(function(){ bort.animate({'width':w}, 1.5*t); borr.animate({'height':h}, 1.5*t); borb.animate({'width':w}, 1.5*t); borl.animate({'height':h}, 1.5*t); },function(){ bort.animate({'width':0}, 1.5*t); borr.animate({'height':0}, 1.5*t); borb.animate({'width':0}, 1.5*t); borl.animate({'height':0}, 1.5*t); }) } if( bor == 't2' ){ bort.css({'left':w/2}); borr.css({'top':h/2}); borb.css({'right':w/2}); borl.css({'bottom':h/2}); border.hover(function(){ bort.animate({'width':w,'left':0}, 1.5*t); borr.animate({'height':h,'top':0}, 1.5*t); borb.animate({'width':w,'right':0}, 1.5*t); borl.animate({'height':h,'bottom':0}, 1.5*t); },function(){ bort.animate({'width':0,'left':w/2}, 1.5*t); borr.animate({'height':0,'top':h/2}, 1.5*t); borb.animate({'width':0,'right':w/2}, 1.5*t); borl.animate({'height':0,'bottom':h/2}, 1.5*t); }) } if( bor == 't3' ){ bort.css({'left':w/2,'top':h/2,'opacity':0}); borr.css({'top':h/2,'right':w/2,'opacity':0}); borb.css({'right':w/2,'bottom':h/2,'opacity':0}); borl.css({'bottom':h/2,'left':w/2,'opacity':0}); border.hover(function(){ bort.animate({'width':w,'left':0,'top':0,'opacity':1}, 1.5*t); borr.animate({'height':h,'top':0,'right':0,'opacity':1}, 1.5*t); borb.animate({'width':w,'right':0,'bottom':0,'opacity':1}, 1.5*t); borl.animate({'height':h,'bottom':0,'left':0,'opacity':1}, 1.5*t); },function(){ bort.animate({'width':0,'left':w/2,'top':h/2,'opacity':0}, 1.5*t); borr.animate({'height':0,'top':h/2,'right':w/2,'opacity':0}, 1.5*t); borb.animate({'width':0,'right':w/2,'bottom':h/2,'opacity':0}, 1.5*t); borl.animate({'height':0,'bottom':h/2,'left':w/2,'opacity':0}, 1.5*t); }) } if( bor == 't4' ){ var tt1 = 'all' + ' ' + t + 'ms' + ' ' + 'ease' + ' ' + '0ms'; var tt2 = 'all' + ' ' + t + 'ms' + ' ' + 'ease' + ' ' + t + 'ms'; var tt3 = 'all' + ' ' + t + 'ms' + ' ' + 'ease' + ' ' + 2*t + 'ms'; var tt4 = 'all' + ' ' + t + 'ms' + ' ' + 'ease' + ' ' + 3*t + 'ms'; border.hover(function(){ bort.css({'width':'100%','-webkit-transition': tt1,'-moz-transition': tt1,'-ms-transition': tt1,'-o-transition': tt1,'transition': tt1}); borr.css({'height':'100%','-webkit-transition': tt2,'-moz-transition': tt2,'-ms-transition': tt2,'-o-transition': tt2,'transition': tt2}); borb.css({'width':'100%','-webkit-transition': tt3,'-moz-transition': tt3,'-ms-transition': tt3,'-o-transition': tt3,'transition': tt3}); borl.css({'height':'100%','-webkit-transition': tt4,'-moz-transition': tt4,'-ms-transition': tt4,'-o-transition': tt4,'transition': tt4}); },function(){ bort.css({'width':0,'-webkit-transition': tt4,'-moz-transition': tt4,'-ms-transition': tt4,'-o-transition': tt4,'transition': tt4}); borr.css({'height':0,'-webkit-transition': tt3,'-moz-transition': tt3,'-ms-transition': tt3,'-o-transition': tt3,'transition': tt3}); borb.css({'width':0,'-webkit-transition': tt2,'-moz-transition': tt2,'-ms-transition': tt2,'-o-transition': tt2,'transition': tt2}); borl.css({'height':0,'-webkit-transition': tt1,'-moz-transition': tt1,'-ms-transition': tt1,'-o-transition': tt1,'transition': tt1}); }); } } // 图片滚动 jQuery.fn.imageScroller = function(params){ var p = params || { direction:"", next:"buttonNext", prev:"buttonPrev", frame:"viewerFrame", width:100, pm:10, child:"a", auto:true }; var _direction = p.direction; var _btnNext = $("#"+ p.next); var _btnPrev = $("#"+ p.prev); var _imgFrame = $("#"+ p.frame); var _width = p.width; var _height = p.height; var _child = p.child; var _auto = p.auto; var _itv; _width=_imgFrame.find(_child+":first").width()+p.pm; _height=_imgFrame.find(_child+":first").height()+p.pm; var turnLeft = function(){ _btnPrev.unbind("click",turnLeft); if(_auto) autoStop(); _imgFrame.animate( {marginLeft:-_width}, 'slow', '', function(){ _imgFrame.find(_child+":first").appendTo( _imgFrame ); _imgFrame.css("marginLeft",0); _btnPrev.bind("click",turnLeft); if(_auto) autoPlay(); }); }; var turnRight = function(){ _btnNext.unbind("click",turnRight); if(_auto) autoStop(); _imgFrame.find(_child+":last").clone().show().prependTo( _imgFrame ); _imgFrame.css("marginLeft",-_width); _imgFrame.animate( {marginLeft:0}, 'slow' ,'', function(){ _imgFrame.find(_child+":last").remove(); _btnNext.bind("click",turnRight); if(_auto) autoPlay(); }); }; var turnTop = function(){ _btnPrev.unbind("click",turnTop); if(_auto) autoStop(); _imgFrame.animate( {marginTop:-_height}, 'slow', '', function(){ _imgFrame.find(_child+":first").appendTo( _imgFrame ); _imgFrame.css("marginTop",0); _btnPrev.bind("click",turnTop); if(_auto) autoPlay(); }); }; var turnDown = function(){ _btnNext.unbind("click",turnDown); if(_auto) autoStop(); _imgFrame.find(_child+":last").clone().show().prependTo( _imgFrame ); _imgFrame.css("marginTop",-_height); _imgFrame.animate( {marginTop:0}, 'slow' ,'', function(){ _imgFrame.find(_child+":last").remove(); _btnNext.bind("click",turnDown); if(_auto) autoPlay(); }); }; if(_direction == 'vertical'){ _btnNext.css("cursor","pointer").click( turnDown ); _btnPrev.css("cursor","pointer").click( turnTop ); var autoPlay = function(){ _itv = window.setInterval(turnTop, 3000); }; }else{ _btnNext.css("cursor","pointer").click( turnRight ); _btnPrev.css("cursor","pointer").click( turnLeft ); var autoPlay = function(){ _itv = window.setInterval(turnLeft, 3000); }; } var autoStop = function(){ window.clearInterval(_itv); }; _imgFrame.hover(function(){ if(_auto) autoStop(); },function(){ if(_auto) autoStop(); if(_auto) autoPlay(); }) if(_auto) autoPlay(); }; // 垂直滚动,如:快速导航滚动 $.fn.extend({ Scroll: function(opt) { var sc = new RunScroll({ name: this.attr('id'), line: opt.line, column: opt.column, speed: opt.speed, timer: opt.timer, action:opt.action }); sc.Run(); } }) function RunScroll(pJso){ _.init(this,pJso,{ line:1, column:1, speed:800, timer:5000, name:'', action:'Top' }); if(!this.name){ //alert('Unspecified tagID [name].') } this.jq=$('#'+this.name); } RunScroll.prototype = { Run: function() { var _this = this.jq.eq(0); //.find("ul:first"); var lineH; var line; if (this.action == 'Top' || this.action == 'Bottom') { lineH = _this.find("li:first").height(); //获取行高 line = this.line ? parseInt(this.line, 10) : parseInt(this.jq.height() / lineH, 10); } else { lineH = _this.find("li:first").width(); //获取列宽 line = this.line ? parseInt(this.line, 10) : parseInt(this.jq.width() / lineH, 10); } var speed = this.speed ? parseInt(this.speed, 10) : 500; //卷动速度,数值越大,速度越慢(毫秒) var timer = this.timer ? parseInt(this.timer, 10) : 3000; //滚动的时间间隔(毫秒) var lineColumn = this.column ? parseInt(this.column, 10) : 1; //每行显示几列 if (line == 0) line = 1; var upHeight = -line * lineH / lineColumn; var animateAction; var animateAction1; switch (this.action) { case 'Top': animateAction = { marginTop: upHeight }; animateAction1 = { marginTop: 0 }; break; case 'Bottom': animateAction = { marginBottom: upHeight }; animateAction1 = { marginBottom: 0 }; break; case 'Left': animateAction = { marginLeft: upHeight }; animateAction1 = { marginLeft: 0 }; break; case 'Right': animateAction = { marginRight: upHeight }; animateAction1 = { marginRight: 0 }; break; } var scrollUp = function() { _this.animate(animateAction, speed, function() { for (i = 1; i <= line; i++) { _this.find("li:first").appendTo(_this); } _this.css(animateAction1); }); } //鼠标事件绑定 _this.hover(function() { clearInterval(this.timeID); }, function() { this.timeID = setInterval(scrollUp, timer); }).mouseout(); } } $(function(){ // 精品推荐 $("#viewer").imageScroller({ next:"next", prev:"prev", frame:"viewerFrame", pm:parseInt($('#viewerFrame').attr('pm')), // 间距 child:"li", auto:true // 是否自动播放 }); // 垂直居中,等比缩放 $('img[t]').each(function(){ var t=$(this); t.loadthumb({ '_img':t, 'maxW':t.width(), 'maxH':t.height(), model:3 // 1:等比缩放 2:垂直居中 3:所有功能 }); }); // 背景跟随鼠标 $('*[d=direction]').each(function(){ var d=$(this); d.MouseDirection({ '_label':d }); }); // 动态描边 $('*[bor]').each(function(){ var bor=$(this); bor.Runborder({ '_border':bor, '_width':2, '_color':'#ff9600', '_time':500 }); }); // 快速导航 $("ul[f=scroll2]").Scroll({ line: 5, column: 5, speed: 800, timer: 3000 }); })