-
2020-12-22 08:55:20
单击图片放大,浏览图片细节,之后再单击回到原始页面,
如果在浏览细节时候,双击图片 会局部放大,也可以双手拖拽放大,
newImage.gif
代码参考
#import "TransImageTool.h"
#define kSCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define kSCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
#define kMaxZoom 3
@interface TransImageTool ()
@property (nonatomic, assign) CGFloat width;
@property (nonatomic, assign) CGFloat height;
@property (nonatomic, assign) BOOL isTwiceTaping;
@property (nonatomic, assign) BOOL isDoubleTapingForZoom;
@property (nonatomic, assign) CGFloat currentScale;
@property (nonatomic, assign) CGFloat offsetY;
@property (nonatomic, assign) CGFloat touchX;
@property (nonatomic, assign) CGFloat touchY;
@property (nonatomic, strong) UIImageView *transImageView;
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIButton *userBtn ;
@property (nonatomic, strong) UIView *userBtnContainer ;
@end
static CGRect oldframe;
@implementation TransImageTool
- (void)showImage:(UIImageView *)avatarImageView{
UIImage *image = avatarImageView.image;
UIWindow *window = [UIApplication sharedApplication].keyWindow;
oldframe = [avatarImageView convertRect:avatarImageView.bounds toView:window];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:oldframe];
imageView.image = image;
self.transImageView = imageView;
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT)];
scrollView.delegate = self;
scrollView.backgroundColor = [UIColor blackColor];
scrollView.maximumZoomScale = 5.0;
CGFloat ratio = _width / _height * kSCREEN_HEIGHT / kSCREEN_WIDTH;
CGFloat min = MIN(ratio, 1.0);
scrollView.minimumZoomScale = min;
self.scrollView = scrollView;
UITapGestureRecognizer *onetap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
[self.scrollView addGestureRecognizer:onetap];
[self.scrollView addSubview:imageView];
UITapGestureRecognizer *tapImgViewTwice = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImgViewHandleTwice:)];
tapImgViewTwice.numberOfTapsRequired = 2;
tapImgViewTwice.numberOfTouchesRequired = 1;
[scrollView addGestureRecognizer:tapImgViewTwice];
//如果双击失败就单击
[onetap requireGestureRecognizerToFail:tapImgViewTwice];
[window addSubview:self.scrollView];
CGFloat imageViewX = 0;
CGFloat imageViewY = (kSCREEN_HEIGHT - image.size.height*kSCREEN_WIDTH/image.size.width) / 2;
CGFloat imageViewW = kSCREEN_WIDTH;
CGFloat imageViewH = image.size.height * kSCREEN_WIDTH/image.size.width;
[UIView animateWithDuration:0.3
animations:^
{
imageView.frame = CGRectMake(imageViewX, imageViewY, imageViewW, imageViewH);
}
completion:^(BOOL finished)
{
}];
}
- (void)hideImage:(UITapGestureRecognizer*)tap
{
UIView *backgroundView = tap.view;
self.userBtnContainer.alpha = 0;
[UIView animateWithDuration:0.3
animations:^
{
self.transImageView.frame = oldframe;
self.scrollView.alpha = 0;
}
completion:^(BOOL finished)
{
[backgroundView removeFromSuperview];
[self.scrollView removeFromSuperview];
[self.userBtnContainer removeFromSuperview];
}];
}
#pragma mark - UIScrollViewDelegate -
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
{
self.currentScale = scale;
}
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return self.transImageView;
}
-(void)scrollViewDidZoom:(UIScrollView *)scrollView
{
CGFloat xcenter = scrollView.center.x;
CGFloat ycenter = scrollView.center.y;
xcenter = scrollView.contentSize.width > kSCREEN_WIDTH?scrollView.contentSize.width / 2 : xcenter;
ycenter = scrollView.contentSize.height > kSCREEN_HEIGHT ?scrollView.contentSize.height / 2 : ycenter;
if(_isDoubleTapingForZoom)//是否是双击放大的
{
if (_touchX>0 && _touchY>0)
{
//点击在图片上
CGFloat transformX = _touchX * kMaxZoom;
CGFloat transformY = _touchY * kMaxZoom;
CGFloat contentW = scrollView.contentSize.width;
CGFloat contentH = scrollView.contentSize.height;
if (transformX + kSCREEN_WIDTH *.5>=contentW)
{
//右边太大。
transformX = kSCREEN_WIDTH*(kMaxZoom-1);
}
else
{
if (transformX-kSCREEN_WIDTH *.5 < 0)
{//左边太小
transformX = 0;
}
else
{
transformX = transformX-kSCREEN_WIDTH *0.5;
}
}
//计算Y
//Y的放大比例跟图片的本身有关,需要从新计算内容的高度和屏幕的尺寸关系
int maxCount = contentH /([UIScreen mainScreen].bounds.size.height);
if (maxCount >= 1)
{
//智能移动到中心
if (transformY-contentH *0.5 < 0)
{
//上边太小,智能移动到边界
transformY = 0;
}
else
{
if (transformY +kSCREEN_HEIGHT *.5 > contentH) {
//下边太大,智能移动到边界
transformY = contentH - kSCREEN_HEIGHT;
}
else
{
transformY = transformY - kSCREEN_HEIGHT *.5;
}
}
}
else
{
if (transformY-contentH *0.5 < 0)
{
//上边太小,智能移动到边界
transformY = 0;
}
else
{
//下边太大,智能移动到边界
transformY = ycenter - kSCREEN_HEIGHT*0.5;
}
}
[scrollView setContentOffset:CGPointMake(transformX, transformY)];
}
else
{
//默认放大位置
[scrollView setContentOffset:CGPointMake(xcenter- kSCREEN_WIDTH *.5, ycenter - kSCREEN_HEIGHT*0.5)];
}
}
[self.transImageView setCenter:CGPointMake(xcenter, ycenter)];
_touchY = 0;
_touchX = 0;
}
-(void)tapImgViewHandleTwice:(UIGestureRecognizer *)sender{
_touchX = [sender locationInView:self.transImageView].x;
_touchY = [sender locationInView:self.transImageView].y;
if (_touchY >CGRectGetHeight(self.transImageView.frame))
{
//如果大于最大的就是在图片外面,默认放大
_touchY = 0;
}
if(_isTwiceTaping)//双击
{
return;
}
_isTwiceTaping = YES;
if(_currentScale > 1.0)
{
_currentScale = 1.0;
[_scrollView setZoomScale:1.0 animated:YES];
}
else
{
_isDoubleTapingForZoom = YES;
_currentScale = kMaxZoom;
[_scrollView setZoomScale:kMaxZoom animated:YES];
}
_isDoubleTapingForZoom = NO;
//延时做标记判断,使用户点击3次时的单击效果不生效。
[self performSelector:@selector(twiceTaping) withObject:nil afterDelay:0.65];
}
-(void)twiceTaping{
_isTwiceTaping = NO;
}
//是否添加其他按钮
- (void)addTooBtnView
{
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, kSCREEN_WIDTH, 80)];
containerView.backgroundColor = [UIColor clearColor];
self.userBtnContainer = containerView;
// [window addSubview:containerView];
/*添加button*/
UIButton *userBtnright = [UIButton buttonWithType:UIButtonTypeSystem];
userBtnright.frame =CGRectMake(kSCREEN_WIDTH - 100, 0, 60, 30);
[userBtnright setTitle:@"正确" forState:UIControlStateNormal];
[userBtnright setBackgroundColor:[UIColor blueColor]];
self.userBtn = userBtnright;
//[containerView addSubview:userBtnright];
/*添加button*/
UIButton *userBtnerror = [UIButton buttonWithType:UIButtonTypeSystem];
userBtnerror.frame =CGRectMake(kSCREEN_WIDTH - 170, 0, 60, 30);
[userBtnerror setTitle:@"错误" forState:UIControlStateNormal];
[userBtnerror setBackgroundColor:[UIColor blueColor]];
self.userBtn = userBtnerror;
//[containerView addSubview:userBtnerror];
}
-(void)dealloc
{
NSLog(@"dealloc");
}
@end
更多相关内容 -
PS放大图片而不模糊的操作方法
2020-02-23 15:20:421、使用ps打开图片(原始图片200*200),正常情况下ctrl + “+” 放大图片,图片会变模糊,如下: 原始图片: 放大之后: 明显模糊了。 2、右键图层,选择复制图层,如下: 3、选中新图层,选择菜单栏的...1、使用ps打开图片(原始图片200*200),正常情况下ctrl + “+” 放大图片,图片会变模糊,如下:
原始图片:
放大之后:
明显模糊了。
2、右键图层,选择复制图层,如下:
3、选中新图层,选择菜单栏的图像--》画布大小;调整画布宽和高,如下:
调整后画布如下:
4、右键复制图层,转换为智能对象
5、ctrl + “t” ,按住shift 拖动放大图像,完成,此时图片放大,没有出现锯齿或像素模糊:
-
Android ImageView图片放大到全屏显示
2018-03-21 17:46:22Android ImageView实现是对图片放大后可以局部的拉伸放大,双击放大 -
HTML点击图片放大
2015-03-24 15:43:41纯HTML和JS,CSS实现的点击图片,图片放大的功能 -
Android中实现WebView点击图片放大显示
2017-01-03 15:45:55Android中实现WebView点击图片放大显示,完整代码demo。 -
h5 - PhotoSwipe图片放大功能集成和使用
2018-05-31 13:53:52PhotoSwipe图片放大功能集成和使用,h5网页中点击图片放大,放大后左右查看滑动,还能分享到各个社区! -
Android图片浏览点击放大
2016-02-17 17:30:53Android图片浏览点击放大源代码,实现方便便捷 -
移动端图片浏览双指放大组件
2015-10-29 11:34:14这是一个移动端图片浏览双指放大组件,暂不支持双击缩放 -
android ScrollView中 下拉放大图片
2015-08-20 10:16:35项目中用到图片下拉放大图片功能 网上没有找到何用的 自己写了一个 在scrollView顶部中加入图片,下拉图片放大,松手后图片回弹 -
仿微信朋友圈图片缩放归位,放大查看功能
2017-03-29 14:49:44仿微信朋友圈图片缩放归位,放大查看功能,我的博客上有相关解析 -
jquery 实现点击图片放大效果
2014-02-21 17:49:21jquery 实现点击图片放大效果 -
双指缩放图片,双击放大缩小图片DEMO
2014-08-03 18:57:52双指缩放图片,双击放大缩小图片DEMO,用的是开源库。 -
photoswipe之移动端图片放大查看,保存到本地
2015-11-11 14:20:48photoswipe之移动端图片放大查看,滑动切换下一张,图片保存到本地。 -
jquery 点击图片放大,再点击缩小(针对同一张图片)
2013-09-27 22:01:11一个简单的 针对同一张图片,点击图片放大,再点击缩小. -
点击图片后放大居中显示
2013-10-29 01:31:12点击图片后放大居中显示,主要是要考虑浏览器的兼容性和样式 -
JS+Html图片放大缩小旋转拖动效果
2014-10-30 11:29:45根据网上找的代码修改后的成品,实现了图片的方法,缩小,旋转,拖动查看等功能 -
图片点击放大到全屏、可以手势缩放
2014-11-24 15:30:48这个效果其实就和新浪微博一样的,不过做的可能没有那么好的...看网上没有这块的,要么是单独的点击图片放大,要么就是缩放的,而且缩放的例子是很多,但是效果都不好看,也不是我要的,这个就是自己结合在了一起了。 -
Android 图片局部放大效果
2013-04-01 11:16:39Android 图片局部放大效果 -
js图片 放大 缩小 移动 鹰眼
2012-10-13 10:31:38现在是按下SHIFT+鼠标左键 放大图片;ALT+鼠标右键 缩小图片 如何修改成 鼠标滑轮向上滚动 放大图片;向下滚动 缩小图片呢? -
js实现图片放大镜效果——简单方法
2021-07-31 11:48:31之前写过一篇关于电商项目商品详情页面的图片放大镜效果:电商项目商品详情页的图片放大效果实现:https://blog.csdn.net/yehaocheng520/article/details/119003274?spm=1001.2014.3001.5501 当时是在vue项目中使用...之前写过一篇关于电商项目商品详情页面的图片放大镜效果:电商项目商品详情页的图片放大效果实现:https://blog.csdn.net/yehaocheng520/article/details/119003274?spm=1001.2014.3001.5501
当时是在vue
项目中使用的,其实跟在js
中原理也是一样的。实现图片放大镜效果的重点就是下面的这张图了:
上面的方法中,右侧图片,为了实现放大,使用的是background
背景图片的设置原理,给background-size
设置大于1的参数,就可以实现图片的放大效果了。下面介绍另一种方法来实现图片放大镜的效果:个人感觉下面的方法更简单。
1.
html
部分代码——左右布局,左侧有图片+选择框,右侧有图片<div class="leftcon" id="left"> <img src="img/风景-1.jpg"> <div class="slide_box" id="box"></div> </div> <div class="rightcon" id="right"> <img src="img/风景-1.jpg"> </div>
2.
css
部分——右侧大图直接设置width
height
百分比超过1,实现放大效果.leftcon{ width: 350px; height: 350px; margin: 100px 20px 0px 312px; float: left; position: relative; box-shadow:3px 3px 10px 0 #111111; /*给图片施加阴影效果 */ -webkit-box-shadow: 3px 3px 10px 0 #111111; /*兼容性处理*/ -moz-box-shadow: 3px 3px 10px 0 #111111; } .leftcon img{ width: 100%; height: 100%; } .leftcon .slide_box{ display:none; /*将小方块盒子隐藏*/ position:absolute; top:0; left:0; width:175px; height:175px; background:#000; opacity: 0.3; cursor:move; /*改变鼠标的形状*/ } .rightcon{ display: none; /*将右边div隐藏*/ width: 350px; height: 350px; margin-top: 100px; float: left; overflow: hidden; position: relative; } .rightcon img{ width: 200%; height: 200%; position: absolute; left: 0px; top: 0px; }
3.
js
部分——关键部分1.首先获取到几个关键的
dom
元素var leftone = document.getElementById('left');//获取左侧部分dom var rightone = document.getElementById('right');//获取右侧部分dom var box = documnent.getElementById('box');//获取选择框dom var rimg = rightone.getElementsByTagName('img')[0];//获取右侧部分中的img数组的第一个
2.需要用到的参数——关于浏览器界面的参数
浏览器点击事件传递的事件源是event,代表对象的状态,比如事件在其中发生的元素、键盘按键的状态、鼠标的位置、鼠标按钮的状态,event是window的一个属性
event || window.event
:就是事件源对象,这样写是为了兼容IE
浏览器
根据上面的图片,我们可以看到几个相关的参数:
e.pageY
:鼠标点击处距离页面最顶部的距离
e.pageX
:鼠标点击处距离页面最左边的距离
oAppTop
:就是左侧图片距离页面顶部的距离:也就是当前案例中的leftone.offsetTop
oAppLeft
:就是左侧图片距离页面左边的距离:也就是当前案例中的leftone.offsetLeft
height
:就是选择框的高度:也就是当前案例中的box.offsetHeight
width
:就是选择框的宽度:也就是当前案例中的box.offsetWidth
通过上面的分析,可以得出:选择框的位置
left
top
的大小:
var top = e.pageY - leftone.offsetTop - box.offsetHeight/2;
var left = e.pageX - leftone.offsetLeft - box.offsetWidth/2;
3.计算选择框出现的边界范围——因为选择框是相对于左侧图片的,因此最小值是0
var maxtop = leftone.offsetHeight - box.offsetHeight;
//选择框的最大top值
var maxleft = leftone.offsetWidth - box.offsetWidth;
//选择框的最大left值
var mintop = 0;
//选择框的最小top值
var minleft = 0;
//选择框的最小left值4.判断选择框的边界范围
代码分析:
top是鼠标到浏览器的垂直距离减去左边div顶部到浏览器的垂直距离减去选择框的高度的一半,那么现在鼠标在选择框的中心,也就是说,top就等于选择框的顶部到左边的div的垂直距离,那么,如果top<0,就是说选择框和左边的div顶部重合,就让选择框的top值为0,即鼠标继续向上移动,选择框不再移动,从而让选择框的移动范围不能超过左边div的宽高范围
if(top < mintop){ box.style.top = mintop + "px"; mvtop = mintop; }else if(top>maxtop){ box.style.top = maxtop+'px'; mvtop = maxtop; }else{ box.style.top = top +'px'; mvtop = top; } if(left < minleft){ box.style.left = minleft + "px"; mvleft = minleft; }else if(left > maxleft){ box.style.left = maxleft + "px"; mvleft = maxleft; }else{ box.style.left = left + 'px'; mvleft = left; }
5.给右侧大图的位置赋值
rimg.style.top = -mvtop*2+‘px’
rimg.style.left = -mvleft*2+'px'
6.监听鼠标移动的事件——
onmouseomve
和onmouseleave
鼠标移动效果
leftone.onmousemove = function(e){ var e = e||window.event;//判断事件源 box.style.display = 'block'; getPosition(e);//这个就是移动鼠标改变右侧图片位置的方法 rightone.style.display = 'block'; }
鼠标移出效果
leftone.onmouseleave = function(e){ var e = e||window.event;//判断事件源 box.style.display = 'none'; rightone.style.display = 'none'; }
完整
html
代码如下<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <link rel="icon" href="img/favicon.ico" type="img/x-ico" /> <title>Image Magnifying Glass</title> <!-- 放大镜的原理: 左边图片100%显示,右边图片200%显示并定位,定义两个图片框,将图片放入,图片超出相框部分隐藏,移动滑块,根据滑块的位置,计算出右边图片的定位,从而形成映射效果,即图片放大镜 --> <style type="text/css"> body { margin: 0px; padding: 0px; } img { /* display: block; */ } .leftcon { width: 350px; height: 350px; margin: 100px 20px 0px 312px; float: left; position: relative; box-shadow: 3px 3px 10px 0 #111111; /*给图片施加阴影效果 */ -webkit-box-shadow: 3px 3px 10px 0 #111111; /*兼容性处理*/ -moz-box-shadow: 3px 3px 10px 0 #111111; } .leftcon img { width: 100%; height: 100%; } .leftcon .slide_box { display: none; /*将小方块盒子隐藏*/ position: absolute; top: 0; left: 0; width: 175px; height: 175px; background: #000; opacity: 0.3; cursor: move; /*改变鼠标的形状*/ } .rightcon { display: none; /*将右边div隐藏*/ width: 350px; height: 350px; margin-top: 100px; float: left; overflow: hidden; position: relative; } .rightcon img { width: 200%; height: 200%; position: absolute; left: 0px; top: 0px; } </style> </head> <body> <div class="leftcon" id="left"> <img src="img/风景-1.jpg" /> <div class="slide_box" id="box"></div> </div> <div class="rightcon" id="right"> <img src="img/风景-1.jpg" /> </div> </body> <script> var leftone = document.getElementById("left"); var rightone = document.getElementById("right"); var box = document.getElementById("box"); var rimg = rightone.getElementsByTagName("img")[0]; // Event是获取事件对象,对象代表事件的状态,比如事件在其中发生的元素、键盘按键的状态、鼠标的位置、鼠标按钮的状态,envet是windows的一个属性。 // 放大镜实现方法(获取右边图片定位) function getPosition(e) { //这里的参数e就是代表event //首先我们要去判断事件源,获取事件源,也就是e var e = e || window.event; //实现兼容 //理解: //这个表达式写全是这样:var e=event?event||window.event; //如果存在event,那么var e=event;而如果不存在event,那么var e=window.event.那么可以看出确实能实现兼容 var top = e.clientY - leftone.offsetTop - box.offsetHeight / 2; var left = e.clientX - leftone.offsetLeft - box.offsetWidth / 2; //理解: //e.clientY:返回事件触发时鼠标相对于元素视口的Y坐标。 //e.clientX:返回事件触发时鼠标相对于元素视口的X坐标。 //这里的元素视口实际上代指就是浏览器,clientX是鼠标距离浏览器左边框的距离,clientY是鼠标距离浏览器上边框的距离。 //offsetTop获取对象相对于版面或由offsetTop属性指定的父坐标的计算顶端位置。这里就是左边的div相对于body即浏览器窗口的纵向距离 //offsetLeft获取对象相对于版面或由offsetLeft属性指定的父坐标的计算顶端位置。这里就是左边的div相对于body即浏览器窗口的纵横向距离 //offsetHeight是对象的可见高度。这里是指小滑块的高度 //offsetHeight是对象的可见宽度。这里是指小滑块的宽度 //这里为什么除以2?是因为我们不除以2的话,事件源也就是鼠标就在这个小滑块的的右下角,并不美观 //我们要让鼠标位于滑块的中心,所以宽高各减去一半 //边界判断 var maxtop = leftone.offsetHeight - box.offsetHeight; //获取小滑块最大纵向移动距离 var maxleft = leftone.offsetWidth - box.offsetWidth; //获取小滑块最大横向移动距离 var mintop = 0; //获取小滑块最小纵向移动距离 var minleft = 0; //获取小滑块最大纵向移动距离 var mvtop; //定义小滑块的纵向移动距离 var mvleft; //定义小滑块的横向移动距离 // 判断 if (top < mintop) { box.style.top = mintop + "px"; mvtop = mintop; //理解: //top是鼠标到浏览器的垂直距离-左边div顶部到浏览器的垂直距离-小滑块的高度的一半。那么现在鼠标在小滑块的中心,也就是说,top就等于小滑块的顶部到左边div的垂直距离 //那么,如果top<0,就是说小滑块和左边div顶部重合,就让小滑块的top值为0,即鼠标继续向上移动,小滑块不在移动,从而让小滑块的移动范围不能超过左边div的宽高范围 //下方同理 } else if (top > maxtop) { box.style.top = maxtop + "px"; mvtop = maxtop; //如果top>maxtop,就是说小滑块和左边div底部重合,就让小滑块的top值为maxtop,即鼠标继续向下移动,小滑块不在移动,从而让小滑块的移动范围不能超过左边div的宽高范围 } else { box.style.top = top + "px"; mvtop = top; //不超过边界,则小滑块的垂直移动距离就等于top,即小滑块的顶部到左边div的垂直距离 } if (left < minleft) { box.style.left = minleft + "px"; mvleft = minleft; } else if (left > maxleft) { box.style.left = maxleft + "px"; mvleft = maxleft; } else { box.style.left = left + "px"; mvleft = left; } //因为右边div的图片是左边div的图片的两倍,而左边div和右边div都是小滑块的宽高的两倍,而要让右边div放大左边的小滑块的包围图片,所以右边大图的定位坐标是小滑块的两倍,这样才能进行映射 //右侧图片跟着运动:左侧小滑块移动多少,右侧跟着移动他的2倍即可 rimg.style.top = -mvtop * 2 + "px"; rimg.style.left = -mvleft * 2 + "px"; } // 左侧盒子鼠标移入,小滑块和右侧图片显示,衔接鼠标移动效果 //onmouseenter 事件类似于 onmouseover 事件。 唯一的区别是 onmouseenter 事件不支持冒泡。 //该事件通常与 onmouseleave 事件一同使用。 // leftone.onmouseenter = function(e){ // var e=e||window.event; //判断事件源 // box.style.display = "block"; // getPosition(e); // rightone.style.display = "block"; // } //鼠标移动效果 leftone.onmousemove = function(e) { var e = e || window.event; //判断事件源 box.style.display = "block"; getPosition(e); rightone.style.display = "block"; }; //鼠标移出效果 leftone.onmouseleave = function(e) { var e = e || window.event; //判断事件源 box.style.display = "none"; rightone.style.display = "none"; }; </script> </html>
-
JS点击图片后图片放大效果
2020-12-30 09:21:52效果图如下 关键代码 <img style="width: 150px;height: 150px;..." src="img/微信图片_20201230091744.jpg" class="img-responsive">..." src="img/微信图片_20201230091800.jpg" class="img-...要实现左右切换效果请转至:https://blog.csdn.net/white1114579650/article/details/111980566
效果图如下
关键代码
<img style="width: 150px;height: 150px;padding: 10px;" src="img/微信图片_20201230091744.jpg" class="img-responsive"> <img style="width: 150px;height: 150px;padding: 10px;" src="img/微信图片_20201230091800.jpg" class="img-responsive"> <div id="outerdiv" style="position:fixed;top:0;left:0;background:rgba(0,0,0,0.7);z-index:2;width:100%;height:100%;display:none;"> <div id="innerdiv" style="position:absolute;"> <img id="bigimg" style="border:5px solid #fff;" src="" /> </div>
js部分
<script src="js/jquery.min.js"></script> <script> $(function() { $(".img-responsive").click(function (){ debugger var _this=$(this); imgShow("#outerdiv","#innerdiv","#bigimg",_this); }); }); function imgShow(outerdiv,innerdiv,bigimg,_this){ debugger var src=_this.attr("src"); $(bigimg).attr("src",src); $("<img/>").attr("src",src).on('load',function () { debugger var windowW=$(window).width() var windowH=$(window).height(); var realWidth=this.width; var readHeight=this.height; var imgWidth,imgHeight; var scale=0.8; if(realWidth>windowW+scale){ imgHeight=windowH*scale; imgWidth=imgHeight/readHeight*realWidth; if(imgWidth>windowW*scale){ imgWidth=windowW*scale; } }else if(realWidth>windowW*scale){ imgWidth=windowW*scale; imgHeight=imgWidth/realWidth*readHeight; }else { imgWidth=realWidth; imgHeight=readHeight; } $(bigimg).css("width",imgWidth); var w=(windowW-imgWidth)/2; var h=(windowH-imgHeight)/2; $(innerdiv).css({"top":h,"left":w}); $(outerdiv).fadeIn("fast"); }); $(outerdiv).click(function (){ $(this).fadeOut("fast"); }); }; </script>
注:必须引入js文件后才有效果!!!
要实现左右切换效果请转至:https://blog.csdn.net/white1114579650/article/details/111980566
-
axure 图片放大效果
2014-07-30 17:46:06图片放大缩小效果 -
C#图片图像像素放大的一个方法
2013-08-24 05:37:11写了一个方法用于处理图片的直接放大(直接放大像素),类似photoshop的放大功能,这个放大用于图片放大后像素的定位和修改,由于使用了指针需要勾选允许不安全代码选项,做成方法是为了方便使用! -
Unity鼠标滑过,图片局部放大效果
2013-05-29 09:17:32Unity中鼠标滑过,图片局部放大效果,像淘宝上商品详细的效果 -
中间图片放大,两边缩小,轮播效果
2016-07-06 13:33:07网上找了很久没找到一个合适的不是效果不好就是有bug,最后自己动手 实现了比较满意的效果 -
html实现点击图片放大功能
2020-11-20 11:01:20<html> <head> <meta charset="UTF-8"/> <title>魔影国际影城全国分布图</title>...meta name="viewport" content="width=device-width,height=device-height;... &... -
下拉放大图片
2015-03-22 20:35:16ListView 下拉放大头部图片实现刷新效果 -
html鼠标放在图片上图片自动放大,css使图片自动放大
2022-03-22 16:48:10目的:将鼠标放在图片上,图片自动放大,鼠标移开后图片大小复原。 实现过程: 方法一:通过hover来控制鼠标放到图片上时图片的大小,通过transition来控制变化的时间。 具体代码如下 <!DOCTYPE html> <... -
ppt 怎么让图片放大完成以后再缩小到原来的大小和位子!!!!
2020-12-30 14:41:47第一步:点击图片【添加动画】【强调】【放大缩小】【较小】或【微小】。第二步:再【添加动画】【动作路径】【直线】或【自定义路径】自己选择路径返回到原点。放大缩小与动作路径可一前一后(即【上一动画之后】)也... -
手机js手势放大缩放图片插件
2015-01-20 14:29:38移动web APP的手势放大缩放图片插件