目前創(chuàng)新互聯(lián)建站已為上千多家的企業(yè)提供了網(wǎng)站建設、域名、雅安服務器托管、綿陽服務器托管、企業(yè)網(wǎng)站設計、清水網(wǎng)站維護等服務,公司將堅持客戶導向、應用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。>var ImgZoom = function (image, viewer, options) {
this._init(image, viewer, options);
}
ImgZoom.prototype= {
_init:function (image, viewer, options) {
this._image = $$O.byId(image); //原圖 this._viewer = $$O.byId(viewer); //顯示框 this._initViewer();
this._MOVE = $$F.bindAsEventListener(this._move, this);
// $$E.addEvent(this._image, "mousemove", this._MOVE); $$E.addEvent(document, "mousemove", this._MOVE);
},
_initViewer:function () {
//初始化顯示框 var viewer = this._viewer;
$(viewer).css({"padding": 0, "overflow": "hidden", "position": "absolute" });
//顯示圖 this._zoom = document.createElement("img");
this._zoom.src = this._image.src;
$(this._zoom).css("position", "absolute");
if (!viewer.contains(this._zoom)) {
viewer.appendChild(this._zoom);
}
},
_move:function (e) {//移動 var self = this, image = this._image, zoom = this._zoom, viewer = this._viewer, x = e.pageX, y = e.pageY;
//原圖位置 var imageRect = {
top: parseInt($(image).offset().top),
left: parseInt($(image).offset().left),
width: parseInt($(image).width()),
height: parseInt($(image).height())
};
$(viewer).show();
if (x > imageRect.left + imageRect.width || x < imageRect.left
|| y > imageRect.top + imageRect.height || y < imageRect.top) {
$(viewer).hide();
}
var pos = {
//(x - imageRect.left):相對圖片的位置 //zoom.width / imageRect.width:原圖、顯示圖的比例 //viewer.offsetWidth:顯示框的寬度,因為需要將圖片放到正中央顯示,因此 viewer.offsetWidth / 2 left: viewer.offsetWidth / 2 - (x - imageRect.left) * (zoom.width / imageRect.width),
top: viewer.offsetHeight/ 2 - (y - imageRect.top) * (zoom.height / imageRect.height)
};
// $$P.log("log", "viewer.offsetWidth=" + viewer.offsetWidth); x = Math.ceil(Math.min(Math.max(pos.left, viewer.offsetWidth - zoom.width), 0));
y= Math.ceil(Math.min(Math.max(pos.top, viewer.offsetHeight - zoom.height), 0));
zoom.style.left= x + "px";
zoom.style.top= y + "px";
}
}
.container{
position: relative; }
.izImage{
width: 300px;
cursor: crosshair; }
.izImage, .izViewer{
border: 1px solid #000;
}
.izViewer{
width: 400px;
height: 400px;
position: absolute;
left: 320px;
top: 0px;
display: none; }
.izViewer div{
position: absolute;
border: dashed 1px #999;
top: 0px;
left: 0px;
z-index: 999;
width: 100%;
height: 100%; }