js image preview method

js part

/图片预览
	$('.popup').hide()
//弹框隐藏
$('.content img').click(function(e){
//向图片元素绑定事件
	console.error(1);
	$('.popup').html(`<div class="popup"><img src="${e.currentTarget.src}" alt=""></div>`)
//渲染到页面
	$('.popup').show()
	$('.shadessk').show()
	document.body.style.overflow='hidden'
	// $('.popup').show()
})
// 确认事件
function cod(){
	$('.shadessk').hide()
	$('.popup').hide()
		sessionStorage.removeItem('ber')
}

Event objects represent the state of an event, such as the element in which the event occurred, the state of keyboard keys, the position of the mouse, and the state of the mouse button.

currentTarget and target are attributes of the event object when listening to specific events

element.addEventListener('click', function (e) {
  // currentTarget 和 target 是 e 的属性
  console.log(e.currentTarget)
  console.log(e.target)
})

the difference

currentTarget is the element the event is bound to. It will never change. In the sample code above, e.currentTarget is the element.

In the case of a click event, the target is the element that the user clicked on. It can be the original element or any of its child elements, depending on where the user clicked

Guess you like

Origin blog.csdn.net/tianxianghuiwei/article/details/134132311