jQuery-图片的放大镜显示效果方法封装
(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> |
jQuery-图片的放大镜显示效果方法封装的更多相关文章
- jQuery-实现图片的放大镜显示效果
jQuery-实现图片的放大镜显示效果 by zhangxinxu from http://www.zhangxinxu.com 本文地址:http://www.zhangxinxu.com/word ...
- [转]jquery 鼠标放在图片上显示图片的放大镜效果jqzoom_ev-2.3
本文转自:http://blog.csdn.net/weizengxun/article/details/6768183 鼠标放在图片上显示图片的放大镜效果使用jqzoom实现,本例版本2.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,但是我们经常会遇到各浏览器表现不一致的情况.基于此,某些情况我 ...
- Jquery图片放大镜
一般在“在线商城.电子商务.企业产品介绍”等地方经常会看到一些图片放大镜的功能,而做这个功能一般是会用一个js包——enlarge.js(这是jquery图片放大镜的插件).Enlarge 是一个基于 ...
- jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想)
jquery中ajax中post方法(多学习:洞悉原理,触类旁通)(函数封装思想) 一.总结 1.多看学习视频:洞悉原理,触类旁通, 2.函数封装:$.post(URL,data,callback); ...
- 使用 jQuery 操作页面元素的方法,实现浏览大图片的效果,在页面上插入一幅小图片,当鼠标悬停到小图片上时,在小图片的右侧出现与之相对应的大图片
查看本章节 查看作业目录 需求说明: 使用 jQuery 操作页面元素的方法,实现浏览大图片的效果,在页面上插入一幅小图片,当鼠标悬停到小图片上时,在小图片的右侧出现与之相对应的大图片 实现思路: 在 ...
- Cropper – 简单的 jQuery 图片裁剪插件
Cropper 是一个简单的 jQuery 图像裁剪插件.它支持选项,方法,事件,触摸(移动),缩放,旋转.输出的裁剪数据基于原始图像大小,这样你就可以用它们来直接裁剪图像. 如果你尝试裁剪跨域图像, ...
- 12款经典的白富美型—jquery图片轮播插件—前端开发必备
图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果.本文向大家推荐12款实用的 jQuery 图片轮播效果插件,帮助你在你的项目中加入一些效果精美 ...
- js jquery 页面加载初始化方法
js jquery 页面加载初始化方法 一.js页面加载初始化方法 // 1.在body里面写初始化方法. <body onload='init()'> </body> < ...
随机推荐
- Oracle第三方ado.net数据提供程序(转)
原文地址:http://www.infoq.com/cn/news/2009/06/oracleclient_deprecated 这项决定有部分原因是基于目前Oracle的第三方ADO.NET数据提 ...
- 【原创】Elasticsearch无宕机迁移节点
官方API文档:https://www.elastic.co/guide/en/elasticsearch/reference/current/allocation-filtering.html 参考 ...
- markdown(语法)入门学习:
原文链接:https://segmentfault.com/a/1190000010223222#articleHeader9 1.标题 注:#后面保持空格 # h1 ## h2 ### h3 ### ...
- 51nod 1244 莫比乌斯函数之和 【莫比乌斯函数+杜教筛】
和bzoj 3944比较像,但是时间卡的更死 设\( f(n)=\sum_{d|n}\mu(d) g(n)=\sum_{i=1}^{n}f(i) s(n)=\sum_{i=1}^{n}\mu(i) \ ...
- pytest特色与实用插件
pytest特色 1.fixture的特点 fixture是pytest特有的功能,其特点如下: 必须用pytest.fixture装饰器装饰:fixture有明确的名字,在其他函数(function ...
- 用代码设置 RelativeLayout.LayoutParams
1.注意 不能在RelativeLayout容器本身和他的子元素之间产生循环依赖,比如说,不能将RelativeLayout的高设置成为WRAP_CONTENT的时候将子元素的高设置成为 ALIGN_ ...
- string.Format 中不能包含{}字符串
string scss = @"<style type=""text/css""> body{ margin-left: {0}px; m ...
- Hackonacci Matrix Rotations 观察题 ,更新了我的模板
https://www.hackerrank.com/contests/w27/challenges/hackonacci-matrix-rotations 一开始是没想到观察题的.只想到直接矩阵快速 ...
- [转]在 Azure 云服务上设计大规模服务的最佳实践
本文转自:http://technet.microsoft.com/zh-cn/magazine/jj717232.aspx 英文版:http://msdn.microsoft.com/library ...
- CSS ul li a 背景图片与文字对齐
<div class="four"> <h2>电子商务</h2> <img src="images/photo2.gif&quo ...