0

0

图片放大镜jquery.jqzoom.js使用实例附放大镜图标

青灯夜游

青灯夜游

发布时间:2018-10-08 16:52:31

|

2700人浏览过

|

来源于脚本之家

转载

这篇文章主要介绍了图片放大镜jquery.jqzoom.js的使用另附放大镜图标,需要的朋友可以参考下


1. jquery.jqzoom.js

//**************************************************************
// jQZoom allows you to realize a small magnifier window,close
// to the image or images on your web page easily.
//
// jqZoom version 2.2
// Author Doc. Ing. Renzi Marco(www.mind-projects.it)
// First Release on Dec 05 2007
// i'm looking for a job,pick me up!!!
// mail: renzi.mrc@gmail.com
//**************************************************************
(function ($) {
$.fn.jqueryzoom = function (options) {
var settings = {
xzoom: 200, //zoomed width default width
yzoom: 200, //zoomed p default width
offset: 10, //zoomed p default offset
position: "right",//zoomed p default position,offset position is to the right of the image
lens: 1, //zooming lens over the image,by default is 1;
preload: 1
};
if (options)
{
$.extend(settings, options);
}
var noalt = '';
$(this).hover(function () {
var imageLeft = $(this).offset().left;
var imageTop = $(this).offset().top;
var imageWidth = $(this).children('img').get(0).offsetWidth;
var imageHeight = $(this).children('img').get(0).offsetHeight;
noalt = $(this).children("img").attr("alt");
var bigimage = $(this).children("img").attr("jqimg");
$(this).children("img").attr("alt", '');
if ($("p.zoomp").get().length == 0)
{
$(this).after("

图片放大镜jquery.jqzoom.js使用实例附放大镜图标

"); $(this).append("

"); } if (settings.position == "right") { if (imageLeft + imageWidth + settings.offset + settings.xzoom > screen.width) { leftpos = imageLeft - settings.offset - settings.xzoom; } else { leftpos = imageLeft + imageWidth + settings.offset; } } else { leftpos = imageLeft - settings.xzoom - settings.offset; if (leftpos < 0) { leftpos = imageLeft + imageWidth + settings.offset; } } $("p.zoomp").css({ top: imageTop, left: leftpos }); $("p.zoomp").width(settings.xzoom); $("p.zoomp").height(settings.yzoom); $("p.zoomp").show(); if (!settings.lens) { $(this).css('cursor', 'crosshair'); } $(document.body).mousemove(function (e) { mouse = new MouseEvent(e); /*$("p.jqZoomPup").hide();*/ 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 = (bigwidth / imageWidth); var scaley = (bigheight / imageHeight); $("p.jqZoomPup").width((settings.xzoom) / scalex); $("p.jqZoomPup").height((settings.yzoom) / scaley); if (settings.lens) { $("p.jqZoomPup").css('visibility', 'visible'); } } xpos = mouse.x - $("p.jqZoomPup").width() / 2 - imageLeft; ypos = mouse.y - $("p.jqZoomPup").height() / 2 - imageTop; if (settings.lens) { xpos = (mouse.x - $("p.jqZoomPup").width() / 2 < imageLeft) ? 0 : (mouse.x + $("p.jqZoomPup").width() / 2 > imageWidth + imageLeft) ? (imageWidth - $("p.jqZoomPup").width() - 2) : xpos; ypos = (mouse.y - $("p.jqZoomPup").height() / 2 < imageTop) ? 0 : (mouse.y + $("p.jqZoomPup").height() / 2 > imageHeight + imageTop) ? (imageHeight - $("p.jqZoomPup").height() - 2) : ypos; } if (settings.lens) { $("p.jqZoomPup").css({ top: ypos, left: xpos }); } scrolly = ypos; $("p.zoomp").get(0).scrollTop = scrolly * scaley; scrollx = xpos; $("p.zoomp").get(0).scrollLeft = (scrollx) * scalex; }); }, function () { $(this).children("img").attr("alt", noalt); $(document.body).unbind("mousemove"); if (settings.lens) { $("p.jqZoomPup").remove(); } $("p.zoomp").remove(); }); count = 0; if (settings.preload) { $('body').append(""); $(this).each(function () { var imagetopreload = $(this).children("img").attr("jqimg"); var content = jQuery('p.jqPreload' + count + '').html(); jQuery('p.jqPreload' + count + '').html(content + '图片放大镜jquery.jqzoom.js使用实例附放大镜图标'); }); } } })(jQuery); function MouseEvent(e) { this.x = e.pageX; this.y = e.pageY; }

2. jqzoom.css

/*jQzoom*/
.jqzoom{
border:1px solid #BBB;
float:left;
position:relative;
padding:0px;
cursor:pointer;
}
p.zoomp {
z-index: 999;
position : absolute;
top:0px;
left:0px;
width : 200px;
height : 200px;
background: #ffffff;
border:1px solid #CCCCCC;
display:none;
text-align: center;
overflow: hidden;
}
p.jqZoomPup {
z-index : 999;
visibility : hidden;
position : absolute;
top:0px;
left:0px;
width : 50px;
height : 50px;
border: 1px solid #aaa;
background: #ffffff url(../images/zoomlens.gif) 50% top no-repeat;
opacity: 0.5;
-moz-opacity: 0.5;
-khtml-opacity: 0.5;
filter: alpha(Opacity=50);
}

3. html代码

京东产品详细页图片放大效果
京东产品详细页图片放大效果

京东商城详细页产品图片列表以及放大镜效果 兼容ie6+,谷歌,火狐 京东商城目前详细页正在使用的放大镜插件,效果很简单易用 图片采用绝对路径,这样方便懒人们使用 内容分为大图部分以及缩略图列表部分,可以分开使用

下载










附件:放大镜图标(zoomlens.gif)

相关专题

更多
jquery插件有哪些
jquery插件有哪些

jquery插件有jQuery UI、jQuery Validate、jQuery DataTables、jQuery Slick、jQuery LazyLoad、jQuery Countdown、jQuery Lightbox、jQuery FullCalendar、jQuery Chosen和jQuery EasyUI等。本专题为大家提供jquery插件相关的文章、下载、课程内容,供大家免费下载体验。

148

2023.09.12

jquery怎么操作json
jquery怎么操作json

操作的方法有:1、“$.parseJSON(jsonString)”2、“$.getJSON(url, data, success)”;3、“$.each(obj, callback)”;4、“$.ajax()”。更多jquery怎么操作json的详细内容,可以访问本专题下面的文章。

305

2023.10.13

jquery删除元素的方法
jquery删除元素的方法

jquery可以通过.remove() 方法、 .detach() 方法、.empty() 方法、.unwrap() 方法、.replaceWith() 方法、.html('') 方法和.hide() 方法来删除元素。更多关于jquery相关的问题,详情请看本专题下面的文章。php中文网欢迎大家前来学习。

388

2023.11.10

jQuery hover()方法的使用
jQuery hover()方法的使用

hover()是jQuery中一个常用的方法,它用于绑定两个事件处理函数,这两个函数将在鼠标指针进入和离开匹配的元素时执行。想了解更多hover()的相关内容,可以阅读本专题下面的文章。

490

2023.12.04

jquery实现分页方法
jquery实现分页方法

在jQuery中实现分页可以使用插件或者自定义实现。想了解更多jquery分页的相关内容,可以阅读本专题下面的文章。

175

2023.12.06

jquery中隐藏元素是什么
jquery中隐藏元素是什么

jquery中隐藏元素是非常重要的一个概念,在使用jquery隐藏元素之前,需要先了解css样式中关于元素隐藏的属性,比如display、visibility、opacity等属性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

115

2024.02.23

jquery中什么是高亮显示
jquery中什么是高亮显示

jquery中高亮显示是指对页面搜索关键词时进行高亮显示,其实现办法:1、先获取要高亮显示的行,获取搜索的内容,再遍历整行内容,最后添加高亮颜色;2、使用“jquery highlight”高亮插件。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

169

2024.02.23

css3教程
css3教程

php中文网为大家提供css3教程合集,CSS3的语法是建立在CSS原先版本基础上的,它允许使用者在标签中指定特定的HTML元素而不必使用多余的class、ID或JavaScript。php中文网还为大家带来css3的相关下载资源、相关课程以及相关文章等内容,供大家免费下载使用。

370

2023.06.14

苹果官网入口直接访问
苹果官网入口直接访问

苹果官网直接访问入口是https://www.apple.com/cn/,该页面具备0.8秒首屏渲染、HTTP/3与Brotli加速、WebP+AVIF双格式图片、免登录浏览全参数等特性。本专题为大家提供相关的文章、下载、课程内容,供大家免费下载体验。

10

2025.12.24

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PHP水印与缩略图最新视频教程
PHP水印与缩略图最新视频教程

共10课时 | 1.7万人学习

jQuery 幻灯片相册教程
jQuery 幻灯片相册教程

共5课时 | 2.1万人学习

前端开发规范手册
前端开发规范手册

共14课时 | 8.5万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号