**create auth houyongxu **/ /** * img onmousemove mouse_out(event,this, 'add_div_img') *
**/ var isCreateImgDivFlg = false; function mouse_out(self){ isCreateImgDivFlg = false; $("#crete_img_bigh_hyx").remove(); $("#create_img_divh_hyx").remove(); } function mouse_move(e, self, show_div){ var e = window.event?window.event:e; /**设置比例**/ var bl = 3//缩小比例 将作为原图和缩略图的比较 var smallX = $(self).width(); /**原图的大小**/ var smallY = $(self).height(); var srcX = smallX * bl; // 大图 var srcY = smallY * bl; var bigX = 300; //预览窗大小,可以任意设置 var bigY = 225; var viewX = bigX / srcX * smallX; //预览范围 var viewY = bigY / srcY * smallY; var img_id = "crete_img_bigh_hyx"; var div_id = "create_img_divh_hyx" ; var border = 0; var iebug = 0; /**判断是否存在**/ if(!isCreateImgDivFlg){ /**创建图片和所包含div**/ var div_str = "
asdf
"; $("#" + show_div).html(div_str); var img_str = ""; $("#" + div_id).html(img_str); isCreateImgDivFlg = true; } if (window.event){ var vX = e.offsetX - viewX/2; var vY = e.offsetY - viewY/2; }else{ var vX = e.pageX - viewX/2 - self.offsetLeft - border; var vY = e.pageY - viewY/2 - self.offsetTop - border; iebug = 2; } if (vX < 0) vX = 0; if (vY < 0) vY = 0; if (vX > smallX - viewX - iebug) vX = smallX - viewX - iebug; if (vY > smallY - viewY - iebug) vY = smallY - viewY - iebug; $("#" + img_id).css("marginLeft",- vX * bl); $("#" + img_id).css("marginTop", - vY * bl); } html代码: