This article shares the specific code of js to realize the enlargement of the picture on the Jingdong details page for your reference. The specific content is as follows Effect: html: <div class="preview_img"> <img src="upload/s3.png" alt=""> <div class="mask"></div> <div class="big"> <img src="upload/big.jpg" alt="" class="bigImg"> </div> </div> css: .preview_img { position: relative; height: 398px; border: 1px solid #ccc; } .mask { display: none; position: absolute; width: 300px; height: 300px; top: 0; left: 0; background: #FEFE4F; opacity: .5; border: 1px solid #ccc; cursor: move; } .big { display: none; position: absolute; width: 550px; height: 550px; top: 0; left: 410px; z-index: 999; border: 1px solid #ccc; overflow: hidden; } .bigimg { position: absolute; left: 0; top: 0; } js (emphasis): window.addEventListener('load',function(){ var preview_img = document.querySelector('.preview_img'); var mask = this.document.querySelector('.mask'); var big = this.document.querySelector('.big'); var bigImg = this.document.querySelector('.bigImg'); //Mouse over preview_img.addEventListener('mouseover',function(){ mask.style.display = 'block'; big.style.display = 'block'; }) //Mouse out preview_img.addEventListener('mouseout',function(){ mask.style.display = 'none'; big.style.display = 'none'; }) //When the mouse moves preview_img.addEventListener('mousemove',function(e){ //The coordinates of the mouse in the box var x = e.pageX - this.offsetLeft; var y = e.pageY - this.offsetTop; //The distance the occlusion layer moves var maskX = x - mask.offsetWidth/2; var maskY = y -mask.offsetHeight/2; //Large image moving distance //Maximum moving distance of occlusion layer var maskMaxX = preview_img.offsetWidth - mask.offsetWidth; var maskMaxY = preview_img.offsetHeight - mask.offsetHeight; //If the X coordinate is less than 0, let it stay at 0 if (maskX <= 0) { maskX = 0; }else if (maskX >= maskMaxX) { maskX = maskMaxX; } //If the Y coordinate is less than 0, let it stay at 0 if (maskY <= 0) { maskY = 0; }else if (maskY >= maskMaxY) { maskY = maskMaxY; } //Occlusion layer movement mask.style.left = maskX + 'px'; mask.style.top = maskY + 'px'; //The maximum moving distance of the big picture var bigMaxX = bigImg.offsetWidth - big.offsetWidth; var bigMaxY = bigImg.offsetHeight - big.offsetHeight; //The moving distance of the large image XY // Moving distance of large image = Moving distance of occlusion layer * Maximum moving distance of large image / Maximum moving distance of occlusion layer var bigX = maskX * bigMaxX / maskMaxX; var bigY = maskY * bigMaxY / maskMaxY; //The big picture and the small picture (mouse movement) are in opposite directions bigImg.style.left = -bigX + 'px'; bigImg.style.top = -bigY + 'px'; }) }) The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: How to Apply for Web Design Jobs
>>: How to set the style of ordered and unordered list items in CSS
This tutorial uses CentOS 7 64-bit. Allocate 2GB ...
mysqlslap Common parameter description –auto-gene...
as follows: -m, --memory Memory limit, the format...
Step 1: Add a secondary domain name to the Alibab...
Google's goal with Flutter has always been to...
Ubuntu 20.04 has been released, bringing many new...
1. Use the <a> tag to complete <a href=&...
Recently, students from the User Experience Team o...
Table of contents Variable Scope The concept of c...
effect: The GROUP_CONCAT function can concatenate...
What is ZooKeeper ZooKeeper is a top-level projec...
Table of contents The role of foreign keys mysql ...
If you want the path following the domain name to...
To summarize the form submission method: 1. Use t...
1. Help Command 1. View the current Docker versio...