(function($){$.fn.imagezoom=function(options){var settings={xzoom:310,yzoom:310,offset:10,position:"btr",preload:1};if(options){$.extend(settings,options);}
var noalt='';var self=this;$(this).bind("mouseenter",function(ev){var imageleft=$(this).offset().left;var imagetop=$(this).offset().top;var imagewidth=$(this).get(0).offsetwidth;var imageheight=$(this).get(0).offsetheight;var boxleft=$(this).parent().offset().left;var boxtop=$(this).parent().offset().top;var boxwidth=$(this).parent().width();var boxheight=$(this).parent().height();noalt=$(this).attr("alt");var bigimage=$(this).attr("rel");$(this).attr("alt",'');if($("div.zoomdiv").get().length==0){$(document.body).append("
");}
if(settings.position=="btr"){if(boxleft+boxwidth+settings.offset+settings.xzoom>screen.width){leftpos=boxleft-settings.offset-settings.xzoom;}else{leftpos=boxleft+boxwidth+settings.offset;}}else{leftpos=imageleft-settings.xzoom-settings.offset;if(leftpos<0){leftpos=imageleft+imagewidth+settings.offset;}}
$("div.zoomdiv").css({top:boxtop,left:leftpos});$("div.zoomdiv").width(settings.xzoom);$("div.zoomdiv").height(settings.yzoom);$("div.zoomdiv").show();$(this).css('cursor','crosshair');$(document.body).mousemove(function(e){mouse=new mouseevent(e);if(mouse.ximageleft+imagewidth||mouse.yimagetop+imageheight){mouseoutimage();return;}
var bigwidth=$(".bigimg").get(0).offsetwidth;var bigheight=$(".bigimg").get(0).offsetheight;var scaley='x';var scalex='y';if(isnan(scalex)|isnan(scaley)){var scalex=(bigwidth/imagewidth);var scaley=(bigheight/imageheight);$("div.zoommask").width((settings.xzoom)/scalex);$("div.zoommask").height((settings.yzoom)/scaley);$("div.zoommask").css('visibility','visible');}
xpos=mouse.x-$("div.zoommask").width()/2;ypos=mouse.y-$("div.zoommask").height()/2;xposs=mouse.x-$("div.zoommask").width()/2-imageleft;yposs=mouse.y-$("div.zoommask").height()/2-imagetop;xpos=(mouse.x-$("div.zoommask").width()/2imagewidth+imageleft)?(imagewidth+imageleft-$("div.zoommask").width()):xpos;ypos=(mouse.y-$("div.zoommask").height()/2imageheight+imagetop)?(imageheight+imagetop-$("div.zoommask").height()):ypos;$("div.zoommask").css({top:ypos,left:xpos});$("div.zoomdiv").get(0).scrollleft=xposs*scalex;$("div.zoomdiv").get(0).scrolltop=yposs*scaley;});});function mouseoutimage(){$(self).attr("alt",noalt);$(document.body).unbind("mousemove");$("div.zoommask").remove();$("div.zoomdiv").remove();}
count=0;if(settings.preload){$('body').append("");$(this).each(function(){var imagetopreload=$(this).attr("rel");var content=jquery('div.jqpreload'+count+'').html();jquery('div.jqpreload'+count+'').html(content+'');});}}})(jquery);function mouseevent(e){this.x=e.pagex;this.y=e.pagey;}
//图片预览小图移动效果,页面加载时触发
$(function(){
var templength = 0; //临时变量,当前移动的长度
var viewnum = 4; //设置每次显示图片的个数量
var movenum = 1; //每次移动的数量
var movetime = 300; //移动速度,毫秒
var scrolldiv = $(".list .thumb ul"); //进行移动动画的容器
var scrollitems = $(".list .thumb ul li"); //移动容器里的集合
var movelength = scrollitems.eq(0).height() * movenum; //计算每次移动的长度
var countlength = (scrollitems.length - viewnum) * scrollitems.eq(0).height(); //计算总长度,总个数*单个长度
//下一张
$(".list .next").bind("click",function(){
if(templength < countlength){
if((countlength - templength) > movelength){
scrolldiv.animate({top:"-=" + movelength + "px"}, movetime);
templength += movelength;
}else{
scrolldiv.animate({top:"-=" + (countlength - templength) + "px"}, movetime);
templength += (countlength - templength);
}
}
});
//上一张
$(".list .prev").bind("click",function(){
if(templength > 0){
if(templength > movelength){
scrolldiv.animate({top: "+=" + movelength + "px"}, movetime);
templength -= movelength;
}else{
scrolldiv.animate({top: "+=" + templength + "px"}, movetime);
templength = 0;
}
}
});
});