/*
本网站效果由昆明天度网络iris原创制作,未经同意不得转载
商城用商品展示放大镜效果
*/
jquery.ljsglasses = {
pcglasses:function(_obj){
var _box = $("#"+_obj.boxid);
var _sum = $("#"+_obj.sumid);
var _last,_next;
var _imgarr = _box.find("img");
var _length = _imgarr.length;
var _index = 0;
var _arr = new array();
_sum.append("
");
var _sumbox = _sum.find("p");
for(var i=0;i<_length;i++){
_arr[i] = new array();
_arr[i][0] = _imgarr.eq(i).attr("src");
_arr[i][1] = _imgarr.eq(i).attr("width");
_arr[i][2] = _imgarr.eq(i).attr("height");
var _scale = _arr[i][1]/_arr[i][2];
if(_scale == 1){
_arr[i][3] = _obj.boxw;//width
_arr[i][4] = _obj.boxh;//height
_arr[i][5] = 0;//top
_arr[i][6] = 0;//left
_arr[i][7] = _obj.boxw/2;
_arr[i][8] = _obj.boxw*2;//width
_arr[i][9] = _obj.boxh*2;//height
_sumbox.append("");
}
if(_scale > 1){
_arr[i][3] = _obj.boxw;//width
_arr[i][4] = _obj.boxw/_scale;
_arr[i][5] = (_obj.boxh-_arr[i][4])/2;
_arr[i][6] = 0;//left
_arr[i][7] = _arr[i][4]/2;
_arr[i][8] = _obj.boxh*2*_scale;//width
_arr[i][9] = _obj.boxh*2;//height
var _place = _obj.sumh - (_obj.sumw/_scale);
_place = _place/2;
_sumbox.append("");
}
if(_scale < 1){
_arr[i][3] = _obj.boxh*_scale;//width
_arr[i][4] = _obj.boxh;//height
_arr[i][5] = 0;//top
_arr[i][6] = (_obj.boxw-_arr[i][3])/2;
_arr[i][7] = _arr[i][3]/2;
_arr[i][8] = _obj.boxw*2;//width
_arr[i][9] = _obj.boxw*2/_scale;
var _place = _obj.sumw - (_obj.sumh*_scale);
_place = _place/2;
_sumbox.append("");
}
}
_imgarr.remove();
_sum.append("");
var _sumarr = _sum.find("span");
var _sumimg = _sum.find("img");
_sumarr.eq(_index).addclass(_obj.sumsel);
var _border = _obj.sumborder*2 + _obj.sumh;
var _sumwidth = (_border+_obj.sumi)*_obj.sums;
var _sumboxwidth = (_border+_obj.sumi)*_length;
_sum.css({
"overflow":"hidden",
"height":_border+"px",
"width":_sumwidth+"px",
"position":"relative"
});
_sumbox.css({
"width":_sumboxwidth+"px"
});
_sumarr.css({
"float":"left",
"margin-left":_obj.sumi+"px",
"width":_obj.sumw+"px",
"height":_obj.sumh+"px",
"overflow":"hidden",
"position":"relative"
});
_sumimg.css({
"max-width":"100%",
"max-height":"100%",
"position":"relative"
});
_box.append("");
var _glass = _box.find("span");
var _boximg = _box.find("b img");
var _imgout = _box.find("div");
var _showbox = _box.find("p");
var _showimg = _box.find("p img");
_box.css({
"width":_obj.boxw+"px",
"height":_obj.boxh+"px",
"position":"relative"
});
var _showboxleft = _obj.boxw + 10;
_showbox.css({
"width":_obj.boxw+"px",
"height":_obj.boxh+"px",
"left":_showboxleft+"px"
});
var imgplaces = function(){
_showimg.attr("src",_arr[_index][0]);
_boximg.attr("src",_arr[_index][0]);
_boximg.css({
"width":_arr[_index][3]+"px",
"height":_arr[_index][4]+"px"
});
_imgout.css({
"width":_arr[_index][3]+"px",
"height":_arr[_index][4]+"px",
"top":_arr[_index][5]+"px",
"left":_arr[_index][6]+"px",
"position":"relative"
});
_glass.css({
"width":_arr[_index][7]+"px",
"height":_arr[_index][7]+"px"
});
_showimg.css({
"width":_arr[_index][8]+"px",
"height":_arr[_index][9]+"px"
});
};
imgplaces();
_imgout.mousemove(function(e){
var _gl_w = _glass.width()/2;
var _maxx = _imgout.width() - _gl_w;
var _maxy = _imgout.height() - _gl_w;
var _movex = 0,_movey = 0;
var _nowx = e.pagex - _imgout.offset().left;
var _nowy = e.pagey - _imgout.offset().top;
var _movex = _nowx-_gl_w,_movey = _nowy-_gl_w;
if(_nowx <= _gl_w){ _movex = 0; }
if(_nowx >= _maxx){ _movex = _maxx-_gl_w; }
if(_nowy <= _gl_w){ _movey = 0;}
if(_nowy >= _maxy){ _movey = _maxy-_gl_w;}
_glass.css({"left":_movex+"px","top":_movey+"px"});
var _imgx = -_movex*_showbox.width()/_glass.width();
var _imgy = -_movey*_showbox.width()/_glass.width();
_showimg.css({"left":_imgx+"px","top":_imgy+"px"});
});//mouse end
_imgout.mouseenter(function(){
_glass.css("display","block");
_showbox.css("display","block");
});
_imgout.mouseleave(function(){
_glass.css("display","none");
_showbox.css("display","none");
});
//列表部分
var _nextbtn = $("#"+_obj.nextid);
var _lastbtn = $("#"+_obj.lastid);
var _moveindex = 0;//索引移动
var _sumlistmove = function(){
var _leftmove = -_moveindex*(_border+_obj.sumi);
if(_sumbox.is(":animated")){_sumbox.stop(true,true);}
_sumbox.animate({left:_leftmove+"px"},300);
_sumarr.eq(_index).addclass(_obj.sumsel).siblings().removeclass(_obj.sumsel);
imgplaces();
};//fun end
if(_length <= _obj.sums){
var _place = (_obj.sums-_length)*_border/2;
_sumbox.css("left",_place+"px");
_nextbtn.click(function(){
_index++;
if(_index >= _length){ _index=_length-1;}
_sumarr.eq(_index).addclass(_obj.sumsel).siblings().removeclass(_obj.sumsel);
imgplaces();
});
_lastbtn.click(function(){
_index--;
if(_index <= 0){ _index=0;}
_sumarr.eq(_index).addclass(_obj.sumsel).siblings().removeclass(_obj.sumsel);
imgplaces();
});
}else{
var _maxnum = _length-_obj.sums;
_nextbtn.click(function(){
_moveindex++;
if(_moveindex >= _maxnum){ _moveindex=_maxnum; }
if(_index <= _moveindex){ _index=_moveindex;}
_sumlistmove();
});
_lastbtn.click(function(){
_moveindex--;
if(_moveindex <= 0){ _moveindex=0;}
if(_index >= _moveindex+_obj.sums){ _index=_moveindex+_obj.sums-1;}
_sumlistmove();
});
}//if end
_sumarr.hover(function(){
_index = $(this).index();
_sumarr.eq(_index).addclass(_obj.sumsel).siblings().removeclass(_obj.sumsel);
imgplaces();
});
}//pcglasses end
}//ljsglasses end