jquery 实现 图片放大

<!DOCTYPE html>
<html>
<head>
<title>enlarge-img</title>
<meta charset="utf-8">
<script type="text/javascript" src="jquery-2.1.1.min.js"></script>

<style>
#enlarge-div {
    position: fixed;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2;
    width: 100%;
    height: 100%;
    display: none;
}
 
#enlarge-div:hover {
    cursor: zoom-out;
}
 
#enlarge-div #inner-div {
    width: 80%;
    height: 85%;
    margin: 0 auto;
    position: relative;
    top: 50%;
    transform: translateY(-50%);
}
 
#enlarge-div #inner-div #big-img {
    max-width: 100%;
    max-height: 100%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translateY(-50%) translateX(-50%);
}


.enlarge-img {  
	cursor: zoom-in;  
	transition: all 0.6s;  
}

.enlarge-img:hover {  
	transform: scale(1.4);  
}

</style>
</head>
<body>

	<h1>jquery 图片放大</h1>

	<img class="enlarge-img" src="https://images.pexels.com/photos/459225/pexels-photo-459225.jpeg?auto=compress&cs=tinysrgb"    style="height:80px; max-width:80px;">
	<img class="enlarge-img" src="https://images.pexels.com/photos/620337/pexels-photo-620337.jpeg?auto=compress&cs=tinysrgb"    style="height:80px; max-width:80px;">
	<img class="enlarge-img" src="https://images.pexels.com/photos/2088167/pexels-photo-2088167.jpeg?auto=compress&cs=tinysrgb"  style="height:80px; max-width:80px;">
	<img class="enlarge-img" src="https://images.pexels.com/photos/1658967/pexels-photo-1658967.jpeg?auto=compress&cs=tinysrgb"  style="height:80px; max-width:80px;" >
	 
	<div id="enlarge-div">
		<div id="inner-div">
			<img id="big-img" src=""/>
		</div>
	</div>



<script type="text/javascript">

$(function () {
	$(".enlarge-img").click(function () {
		$("#big-img").attr("src", $(this).attr("src"));//设置#big-img元素的src属性

		$("#enlarge-div").fadeIn("fast");//显示弹出层

		$("#enlarge-div").click(function () {//关闭弹出层
			$(this).fadeOut("fast");
		});
	});
});
</script>
</body>
</html>

很简单的放大观看

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值