In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about how to use js simulation to achieve JD.com details page picture magnification. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The details are as follows
Effect:
Html:
Css:
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;}. Big img {position: absolute; left: 0 Top: 0;}
Js (key points):
Window.addEventListener ('load',function () {var preview_img = document.querySelector (' .mask _ 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';}) / / move the mouse out of 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 to move the occlusion layer var maskX = x-mask.offsetWidth/2; var maskY = y-mask.offsetHeight/2 / / large image moving distance / / the maximum moving distance of the occlusion layer var maskMaxX = preview_img.offsetWidth-mask.offsetWidth; var maskMaxY = preview_img.offsetHeight-mask.offsetHeight; / / if the X coordinate is less than 0, leave it at 0 position if (maskX = maskMaxX) {maskX = maskMaxX } / / if the Y coordinate is less than 0, let it stay at 0 position if (maskY = maskMaxY) {maskY = maskMaxY;} / / the occlusion layer moves mask.style.left = maskX + 'px'; mask.style.top = maskY +' px' / / maximum moving distance of large picture var bigMaxX = bigImg.offsetWidth-big.offsetWidth; var bigMaxY = bigImg.offsetHeight-big.offsetHeight; / / moving distance of large picture X Y / / moving distance of large picture = moving distance of occlusion layer * maximum moving distance of large picture / maximum moving distance of occlusion layer var bigX = maskX * bigMaxX / maskMaxX Var bigY = maskY * bigMaxY / maskMaxY; / / the big image and the small image (mouse movement) go in the opposite direction bigImg.style.left =-bigX + 'px'; bigImg.style.top =-bigY +' px';})}) Thank you for reading! On "how to use js simulation to achieve JD.com details page picture magnification effect" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.