js之圖片放大

來源:互聯網
上載者:User

標籤:timer   idt   owb   放大鏡   html   contain   query   dem   .sh   

/*
*
* JQUERY 之簡易放大鏡外掛程式
* Author:翅膀的初衷 4585839
* Date:2011-11-16
*
demo:
<input type="text" value="c-img.jpg" id="source" />
<script>
var div = ‘<div id="ShowBigPictureBox" style=" position:absolute; top:20px; left:250px; display:none; background-repeat:no-repeat; background-color:#fff; width:500px;"></div>‘;
$("body").append(div);
$("#source").JNMagnifier({
renderTo:"#ShowBigPictureBox"
});
</script>
*/
(function ($) {
$.fn.JNMagnifier = function (targetContainer) {

if (targetContainer && targetContainer.renderTo) {
if (typeof (targetContainer.renderTo) == "string") {
targetContainer.renderTo = $(targetContainer.renderTo);
}
} else {
return;
}
var _img_org_ = this;

var __w = 0;
var __h = 0;

var __left = this.offset().left;
var __top = this.offset().top;

if (this.offsetParent()) {
__left += this.offsetParent().offset().left;
__top += this.offsetParent().offset().top;
}

var _move_x = 0;
var _move_y = 0;

var _val_w = (targetContainer.renderTo.width() / 2);
var _val_h = (targetContainer.renderTo.height() / 2);

_img_org_.mouseover(function () {


targetContainer.renderTo.html(‘<img src="‘ + _img_org_.val() + ‘" style="position:absolute; max-width:100%" id="JNMagnifierrenderToImg" />‘);
targetContainer.renderTo.show();
var timer = setInterval(function () {
__w = $("#JNMagnifierrenderToImg").width() / _img_org_.width();
__h = $("#JNMagnifierrenderToImg").height() / _img_org_.height();
if (__w > 0) {
clearInterval(timer);
}
}, 100);
});

_img_org_.mouseout(function () {
targetContainer.renderTo.hide();
});

_img_org_.mousemove(function (e) {
_move_x = 0 - Math.round((document.documentElement.scrollLeft + e.clientX - __left) * __w - _val_w);
_move_y = 0 - Math.round((document.documentElement.scrollTop + e.clientY - __top) * __h - _val_h);
//$("#JNMagnifierrenderToImg").css({"left":_move_x + "px ","top":_move_y + "px"});
});
}
})(jQuery);

js之圖片放大

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.