【popup 放大图片】

本帖于 2017-03-07 07:21:58 时间, 由普通用户 弓尒 编辑
回答: 【pop-up 新页面图片放大 连续几张】弓尒2017-03-07 06:58:32

 

Try changing the SASS $dimension value!

=================

Try changing the SASS $dimension value!

// scope protection ;var Magnifier = (function($){ var LIB = { /* standard selection */ selectors : { magnify : '.magnify' , glass_class : 'glass' // lame , glass : '.glass' , thumb : '.thumb' , active_class : 'active' } , /* remember dom elements */ $el : { } , /* prepare all stuff */ init : function(){ // get dom elements LIB.$el.magnifiers = $(LIB.selectors.magnify); //add glass to each magnifier var $glass = $('

 

').addClass(LIB.selectors.glass_class); // get the native image size of each magnifier source image LIB.$el.magnifiers.each(function(i,o){ var $magnifier = $(o) , $thumb = $magnifier.find(LIB.selectors.thumb) ; // use Image object to get the dimensions var image_object = new Image(); image_object.src = $thumb.attr("src"); // save for later $magnifier.data({"native_w":image_object.width, "native_h":image_object.height}); // attach behaviors $magnifier .mousemove(LIB.behaviors.mousemove) ; // add glass $thumb.before( $glass.clone().css('background-image', 'url(' + $thumb.attr('src') + ')') ); }); }//-- fn init , behaviors : { /* delay for...fade */ fadeDelay : 300 , /* fade in/out glass overlay if mouse is outside container */ isHover : function(cw, ch, mx, my){ return (mx < cw && my < ch && mx > 0 && my > 0); }//-- fn hover , /* move glass overlay */ mousemove : function(e){ var $magnifier = $(this) , offset = $magnifier.offset() // relative position , mx = e.pageX - offset.left // relative to mouse , my = e.pageY - offset.top // relative to mouse , $glass = $magnifier.find(LIB.selectors.glass) , $thumb = $magnifier.find(LIB.selectors.thumb) , rx, ry, bgp // relative ratios , native_width = $magnifier.data('native_w') , native_height = $magnifier.data('native_h') , glass_width = $glass.width() , glass_height = $glass.height() ; if( LIB.behaviors.isHover($magnifier.width(), $magnifier.height(), mx, my) ) { // show $glass.fadeIn(LIB.behaviors.fadeDelay); //The background position of .glass will be changed according to the position //of the mouse over the .small image. So we will get the ratio of the pixel //under the mouse pointer with respect to the image and use that to position the //large image inside the magnifying glass rx = Math.round(mx/$thumb.width()*native_width - glass_width/2)*-1; ry = Math.round(my/$thumb.height()*native_height - glass_height/2)*-1; bgp = rx + "px " + ry + "px"; //The logic is to deduct half of the glass's width and height from the //mouse coordinates to place it with its center at the mouse coordinates $glass.css({ left: mx - glass_width/2 , top: my - glass_height/2 , backgroundPosition: bgp }); }//-- if visible else { // hide $glass.fadeOut(LIB.behaviors.fadeDelay); }//-- if !visible }//-- fn mousemove }//-- behaviors , /* include execution in page, with .ready wrapper */ ready : function(){ // ready $(function(){ // setup LIB.init(); }); }//-- fn ready };////---- LIB return LIB; })(jQuery); // engage Magnifier.ready();

 

所有跟帖: 

【压场 北齐石佛8 】 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (2248 bytes) () 03/07/2017 postreply 07:32:36

【图片放大代码9】--- 一行简单代码即可解决问题 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (1018 bytes) () 03/08/2017 postreply 01:32:08

[test009] -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (952 bytes) () 03/08/2017 postreply 02:07:44

【图片放大缩小还原 代码】 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (1649 bytes) () 03/08/2017 postreply 02:21:48

【图片局部区域放大代码】 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (3032 bytes) () 03/08/2017 postreply 02:25:55

【大小两图放大代码】 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (4739 bytes) () 03/08/2017 postreply 02:57:59

【逐点区域放大】 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (2015 bytes) () 03/08/2017 postreply 03:03:45

【局部放大镜 代码】 -弓尒- 给 弓尒 发送悄悄话 弓尒 的博客首页 (3637 bytes) () 03/08/2017 postreply 03:09:03

请您先登陆,再发跟帖!