移动端图片放大实现

html:

<template>
	<div id="knowledge-base">
		<div class="knowledge-title">{{documentName}}</div>
		<!--<div class="knowledge-path">知识库-后台应用-端口</div>-->
		<div class="knowledge-sub">{{documentSubtitle}}</div>
		<div class="content" v-html="documentContent">
			<!--{{documentContent}}-->
		</div>
	</div>
</template>

js:

	var imgArr = document.querySelectorAll('img');
				console.log(imgArr);
				imgArr.forEach(function (item) {
					item.addEventListener('click',function () {
						console.log(this,111);
						var temp = this.src;
						console.log(temp);
						var objE = document.createElement("div");
						objE.innerHTML = '<div class="bgM" >' +
							'<img src="'+temp+'"  id="img_scan" class="img-custom-img2"/>' +
							'</div>';
						document.body.appendChild(objE.children[0]);
						//退出图片预览事件
						var $bg = document.querySelector(".bgM");
						$bg.onclick = function() {
							var dm = document.querySelector(".bgM");
							document.body.removeChild(dm);
						}
						//阻止事件冒泡
						var $img = document.querySelector(".img-custom-img2");
						$img.onclick = function(event) {
							event.stopPropagation();
						}
					})
					// console.log(item,123);
				})

css:

.bgM{
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;left: 0;right: 0;bottom: 0;
  z-index: 1000;
  background-color: rgba(0,0,0,0.85);
  overflow: hidden;
}
.bgM img{
  width: 100%;
  position: absolute;
  top: 0;left: 0;right: 0;bottom: 0;
  z-index: 1001;
  margin: auto;
}

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值