今天研究了一下jquery plugin --image magnifier 放大器。
原理其实很简单,首先你需要一个大图一个小图(或者是一个图),当在小图中移动,计算位差,把这个位差对应到大图上。
当然你还可以隐藏鼠标。
研究结果如下:
/*
//example
$('selector').loupe({
width: 200, // width of magnifier
height: 150, // height of magnifier
loupe: 'loupe' // css class for magnifier
});
<a id="demo-1" href="bigimage.jpg">
<img src="smallimage.jpg" />
</a>
$('#demo-1').loupe();
.loupe {
cursor: url("blank.png"), url("blank.cur"), none;
}
*/
/**
* loupe - an image magnifier for jQuery
* (C) 2010 jdbartlett, MIT license
* http://github.com/jdbartlett/loupe
*/
(function ($) {
$.fn.loupe = function (arg) {
var options = $.extend({
loupe: 'loupe',
width: 200,
height: 150
}, arg || {});
return this.length ? this.each(function () {
var $this = $(this),
$big, $loupe, $small = $this.is('img') ? $this : $this.find('img:first'),
move, hide = function () {
$loupe.hide();
},
time;
if ($this.data('loupe') != null) {
return $this.data('loupe', arg);
}
move = function (e) {
var os = $small.offset(),
sW = $small.outerWidth(),
sH = $small.outerHeight(),
oW = options.width / 2,
oH = options.height / 2;
//判断是否越界
if (!$this.data('loupe') || e.pageX > sW + os.left + 10 || e.pageX < os.left - 10 || e.pageY > sH + os.top + 10 || e.pageY < os.top - 10) {
return hide();
}
time = time ? clearTimeout(time) : 0;
//移动container
$loupe.show().css({
left: e.pageX - oW,
top: e.pageY - oH
});
//移动大图片
$big.css({
left: -(((e.pageX - os.left) / sW) * $big.width() - oW) | 0,
top: -(((e.pageY - os.top) / sH) * $big.height() - oH) | 0
});
};
//新建大图片的container
$loupe = $('<div />').addClass(options.loupe).css({
width: options.width,
height: options.height,
position: 'absolute',
overflow: 'hidden'
}).append($big = $('<img />').attr('src', $this.attr($this.is('img') ? 'src' : 'href')).css('position', 'absolute')).mousemove(move).hide().appendTo('body');
$this.data('loupe', true).mouseenter(move).mouseout(function () {
time = setTimeout(hide, 10);
});
}) : this;
};
}(jQuery));
出处:
jquery magnifier http://jdbartlett.com/loupe/
or
http://www.dailycoding.com/Posts/imagelens__a_jquery_plugin_for_lens_effect_image_zooming.aspx
分享到:
相关推荐
struts2-jquery-plugin-3.1.0.jar
jQuery-Plugin-for-Client-Side-Image-Resizing-canvasResize
struts2-jquery-plugin-2.0.0 struts2-jquery-plugin-2.0.0 struts2-jquery-plugin-2.0.0
jquery.print-preview.js 浏览器打印插件
ionic3使用cordova-plugin-ImagePicker 插件实现仿微信相册选图。因为直接add plugin 下载不下来。故直接github上下载然后打包上传以便日后使用
赠送jar包:spring-plugin-core-2.0.0.RELEASE.jar; 赠送原API文档:spring-plugin-core-2.0.0.RELEASE-javadoc.jar; 赠送源代码:spring-plugin-core-2.0.0.RELEASE-sources.jar; 赠送Maven依赖信息文件:spring...
赠送jar包:spring-plugin-metadata-2.0.0.RELEASE.jar; 赠送原API文档:spring-plugin-metadata-2.0.0.RELEASE-javadoc.jar; 赠送源代码:spring-plugin-metadata-2.0.0.RELEASE-sources.jar; 赠送Maven依赖信息...
赠送jar包:spring-plugin-metadata-1.2.0.RELEASE.jar; 赠送原API文档:spring-plugin-metadata-1.2.0.RELEASE-javadoc.jar; 赠送源代码:spring-plugin-metadata-1.2.0.RELEASE-sources.jar; 包含翻译后的...
jquery-plugin-boxycv
jquery editable plugin--点击编辑文字插件
将atlassian-universal-plugin-manager-plugin-2.17.13.jar 替换到 jira/atlassian-jira-6.3.6-standalone/atlassian-jira/WEB-INF/atlassian-bundled-plugins/ 重新启动jira 用管理员账户登录jira
- `hadoop2x-eclipse-plugin-master/ivy/library.properties` - `hadoop2x-eclipse-plugin-master/src/contrib/eclipse-plugin/build.xml` 开源源地址: https://github.com/winghc/hadoop2x-eclipse-plugin
破解方法: 方法1:覆盖 \WEB-INF\atlassian-bundled-plugins下的同名文件后...各版本插件的适用产品和版本请参见:https://marketplace.atlassian.com/apps/23915/atlassian-universal-plugin-manager/version-history
hadoop-eclipse-plugin-2.7.3和2.7.7的jar包 hadoop-eclipse-plugin-2.7.3和2.7.7的jar包 hadoop-eclipse-plugin-2.7.3和2.7.7的jar包 hadoop-eclipse-plugin-2.7.3和2.7.7的jar包
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
babel-plugin-transform-require-image-url一个用于转换require Quote的图片资源为url的babel插件示例const image = require ( '../path/image.png' ) ;< img xss=removed> ↓ ↓ ↓ ↓ ↓ ↓const image = '...
jQuery plugin for autocomplete - jQuery自动完成插件
axis2-eclipse-codegen-plugin-1.6.2.zip和axis2-eclipse-service-plugin-1.6.2.zip,解压即可使用
Bootstrap-video-player-jQuery-plugin-master全套dom
hadoop-eclipse-plugin-1.2.1hadoop-eclipse-plugin-1.2.1hadoop-eclipse-plugin-1.2.1hadoop-eclipse-plugin-1.2.1