Use JS to put the mouse on the picture to enlarge and leave to realize the reduction function

  • 2021-10-24 18:59:53
  • OfStack

Use JS to realize the mouse to put on the picture to enlarge and leave to realize the reduction function. The specific code is as follows:


<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
	<div id= 'div_jpg' style="width: 200px;height: 200px;">
		<img src="./128206.jpg" id="img" style="width: 100%;height: 100%;">
	</div>
	<script>
		var img = document.getElementById('img')
		var s1,s2
		console.log(img)
		//  Image enlargement effect 
		i = 100;
		img.addEventListener('mouseover',function(){
			clearInterval(s1);
			s1 = setInterval(function(){
				i+=0.1;
				img.style.width = (i)+'%';
				img.style.height = (i)+'%';
				i = parseFloat(i);
				if(i>=120) clearInterval(s1);
			},1);
		})
		img.addEventListener('mouseout',function(){
			clearInterval(s2);
			s2 = setInterval(function(){
				i-=0.1;
				img.style.width = (i)+'%';
				img.style.height = (i)+'%';
				i = parseFloat(i);
				if(i<=100) clearInterval(s2); 
			})
		})

	</script>
</body>
</html>

Share the source code, like friends click to view:

Based on jQuery plug-in Pinchzoom. js finger touch picture enlargement and reduction effect source code

jquery mouse hover picture zoom in and slide display title effect


Related articles: