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
Table of contents 1.Json string 1.1Json Syntax 1....
Table of contents Background Description Creating...
Table of contents Prefab How to create a prefab T...
Table of contents Two ways to solve the problem o...
Table of contents Preface 1. Use $attrs and $list...
Table of contents Installation-free version of My...
0x0 Parameter verification Most of the parameter ...
This article shares the specific code of js imita...
Table of contents 1. What is DOM 2. Select elemen...
I am using the Ubuntu 16.04 system here. Installa...
This article describes how to install the PHP cur...
Table of contents 1. The original array will be m...
Here is an example code for using regular express...
Table of contents question background Idea & ...
When the height attribute of Text is defined, the ...