(function($){
$.fn.jqueryzoom = function(options){
var settings = {
xzoom: 200, //zoomed width default width
yzoom: 200, //zoomed div default width
offset: 10, //zoomed div default offset
position: "right" //zoomed div default position,offset position is to the right of the image
};
if(options) {
$.extend(settings, options);
}
$(this).hover(function(){
var imageLeft = $(this).get(0).offsetLeft;
var imageRight = $(this).get(0).offsetRight;
var imageTop = $(this).get(0).offsetTop;
var imageWidth = $(this).get(0).offsetWidth;
var imageHeight = $(this).get(0).offsetHeight;
var bigimage = $(this).parent().attr("href");
if($("span.zxx_image_zoom_div").get().length == 0){
$(this).after("<span class='zxx_image_zoom_div'><img class='bigimg' src='"+bigimage+"'/></span>");
}
if(settings.position == "right"){
leftpos = imageLeft + imageWidth + settings.offset;
}else{
leftpos = imageLeft - settings.xzoom - settings.offset;
}
$("span.zxx_image_zoom_div").css({ top: imageTop,left: leftpos });
$("span.zxx_image_zoom_div").width(settings.xzoom);
$("span.zxx_image_zoom_div").height(settings.yzoom);
$("span.zxx_image_zoom_div").show();
$(document.body).mousemove(function(e){
var bigwidth = $(".bigimg").get(0).offsetWidth;
var bigheight = $(".bigimg").get(0).offsetHeight;
var scaley ='x';
var scalex= 'y';
if(isNaN(scalex)|isNaN(scaley)){
var scalex = Math.round(bigwidth/imageWidth) ;
var scaley = Math.round(bigheight/imageHeight);
}
mouse = new MouseEvent(e);
scrolly = mouse.y - imageTop - ($("span.zxx_image_zoom_div").height()*1/scaley)/2 ;
$("span.zxx_image_zoom_div").get(0).scrollTop = scrolly * scaley ;
scrollx = mouse.x - imageLeft - ($("span.zxx_image_zoom_div").width()*1/scalex)/2 ;
$("span.zxx_image_zoom_div").get(0).scrollLeft = (scrollx) * scalex ;
});
},function(){
$("span.zxx_image_zoom_div").hide();
$(document.body).unbind("mousemove");
$(".lenszoom").remove();
$("span.zxx_image_zoom_div").remove();
});
}
})(jQuery); function MouseEvent(e) {
this.x = e.pageX
this.y = e.pageY
} //实例
<script type="text/javascript">
  jQuery.noConflict();
  jQuery(document).ready(function(){
  $("img.zxx_zoom_image").jqueryzoom();
  });
  </script>
<div class="zxx_main_con">
  <a href="//image.zhangxinxu.com/image/study/s/s512/mm1.jpg" class="zxx_image_zoom_list">
  <img class="zxx_zoom_image" src="//image.zhangxinxu.com/image/study/s/s128/mm1.jpg" />
  </a>
  <a href="//image.zhangxinxu.com/image/study/s/s512/mm2.jpg" class="zxx_image_zoom_list">
  <img class="zxx_zoom_image" src="//image.zhangxinxu.com/image/study/s/s128/mm2.jpg" />
  </a>
  <a href="//image.zhangxinxu.com/image/study/s/s512/mm3.jpg" class="zxx_image_zoom_list">
  <img class="zxx_zoom_image" src="//image.zhangxinxu.com/image/study/s/s128/mm3.jpg" />
  </a>
  <a href="//image.zhangxinxu.com/image/study/s/s512/mm4.jpg" class="zxx_image_zoom_list">
  <img class="zxx_zoom_image" src="//image.zhangxinxu.com/image/study/s/s128/mm4.jpg" />
  </a>
  <a href="//image.zhangxinxu.com/image/study/s/s512/mm5.jpg" class="zxx_image_zoom_list">
  <img class="zxx_zoom_image" src="//image.zhangxinxu.com/image/study/s/s128/mm5.jpg" />
  </a>
  <a href="//image.zhangxinxu.com/image/study/s/s512/mm6.jpg" class="zxx_image_zoom_list">
  <img class="zxx_zoom_image" src="//image.zhangxinxu.com/image/study/s/s128/mm6.jpg" />
  </a>
  </div>

jQuery-图片的放大镜显示效果方法封装的更多相关文章

  1. jQuery-实现图片的放大镜显示效果

    jQuery-实现图片的放大镜显示效果 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/word ...

  2. [转]jquery 鼠标放在图片上显示图片的放大镜效果jqzoom_ev-2.3

    本文转自:http://blog.csdn.net/weizengxun/article/details/6768183 鼠标放在图片上显示图片的放大镜效果使用jqzoom实现,本例版本2.3 效果图 ...

  3. 史上最全的CSS hack方式一览 jQuery 图片轮播的代码分离 JQuery中的动画 C#中Trim()、TrimStart()、TrimEnd()的用法 marquee 标签的使用详情 js鼠标事件 js添加遮罩层 页面上通过地址栏传值时出现乱码的两种解决方法 ref和out的区别在c#中 总结

    史上最全的CSS hack方式一览 2013年09月28日 15:57:08 阅读数:175473 做前端多年,虽然不是经常需要hack,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...

  4. Jquery图片放大镜

    一般在“在线商城.电子商务.企业产品介绍”等地方经常会看到一些图片放大镜的功能,而做这个功能一般是会用一个js包——enlarge.js(这是jquery图片放大镜的插件).Enlarge 是一个基于 ...

  5. jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想)

    jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想) 一.总结 1.多看学习视频:洞悉原理,触类旁通, 2.函数封装:$.post(URL,data,callback); ...

  6. 使用 jQuery 操作页面元素的方法,实现浏览大图片的效果,在页面上插入一幅小图片,当鼠标悬停到小图片上时,在小图片的右侧出现与之相对应的大图片

    查看本章节 查看作业目录 需求说明: 使用 jQuery 操作页面元素的方法,实现浏览大图片的效果,在页面上插入一幅小图片,当鼠标悬停到小图片上时,在小图片的右侧出现与之相对应的大图片 实现思路: 在 ...

  7. Cropper – 简单的 jQuery 图片裁剪插件

    Cropper 是一个简单的 jQuery 图像裁剪插件.它支持选项,方法,事件,触摸(移动),缩放,旋转.输出的裁剪数据基于原始图像大小,这样你就可以用它们来直接裁剪图像. 如果你尝试裁剪跨域图像, ...

  8. 12款经典的白富美型—jquery图片轮播插件—前端开发必备

    图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...

  9. js jquery 页面加载初始化方法

    js jquery 页面加载初始化方法 一.js页面加载初始化方法 // 1.在body里面写初始化方法. <body onload='init()'> </body> < ...

随机推荐

  1. zoj 3861(dfs)

    Valid Pattern Lock Time Limit: 2 Seconds      Memory Limit: 65536 KB Pattern lock security is genera ...

  2. 杂项-Java:JBoss

    ylbtech-杂项-Java:JBoss 是一个基于J2EE的开放源代码的应用服务器. JBoss代码遵循LGPL许可,可以在任何商业应用中免费使用.JBoss是一个管理EJB的容器和服务器,支持E ...

  3. SpringBoot使用MongoDB

    一.什么是MongoDB MongoDB是一个基于分布式文件存储的数据库,由C++语言编写.旨在为WEB应用提供可扩展的高性能数据存储解决方案. MongoDB是一个介于关系数据库和非关系数据库之间的 ...

  4. iOS NSDictionary <--> NSString(JSON) in Objc

    NSDictionary --> NSString + (NSString*)stringINJSONFormatForObject:(id)obj { NSData *jsonData = [ ...

  5. Allure对单测结果以及robotframework结果的处理

    Allure对单测结果以及robotframework结果的处理 Allure只能针对pytest的单测结果生成相应的报告: 如果需要对unittest的测试框架结果进行展示,可以使用pytest执行 ...

  6. MyEclipse去除不必要的validation

    MyEclipse在构建项目时去除不必要的Valication可以加快构建速度. 操作: Window->Perferences->MyEclipse->Validation 在Va ...

  7. Tenegrad评价函数 分类: 图像处理 Opencv 2014-11-12 20:46 488人阅读 评论(0) 收藏

    Tenegrad函数式一种常用的图像清晰度评价函数,是一种基于梯度的函数. 在图像处理中,一般认为对焦好的图像具有更尖锐的边缘,故具有更大的梯度函数值. Tenegrad函数使用Sobel算子提取水平 ...

  8. 框架系列~OwinSelfHost自宿主的使用

    在进入mvc5之后,OWIN变更很主推,很热,关于OWIN的文章也就出来了,下面阅读了dudu和一些园友的文章,自己也做了一个SelfHost的程序,测试了一下,感觉还是比较有Core的风格,可能也是 ...

  9. Spring @Resource、@Autowired、@Qualifier区别

    @Resource默认是按照名称来装配注入的,只有当找不到与名称匹配的bean才会按照类型来装配注入: @Autowired默认是按照类型装配注入的,如果想按照名称来转配注入,则需要结合@Qualif ...

  10. poj3685 Matrix

    思路: 二分套二分. 矩阵在每一列上是严格递增的,可以利用这一点进行二分. 实现: #include <cstdio> #include <cmath> #include &l ...