This article shares the specific code for JavaScript to achieve the accordion effect for your reference. The specific content is as follows Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> * { margin: 0; padding: 0; } ul { width: 100%; text-align: center; } ul li { list-style: none; overflow: hidden; display: inline-block; transition: all 1s; } </style> </head> <body> <ul> </ul> <script> var ul = document.querySelector("ul"); var imgs = ["img/img4.jpg", "img/img5.jpg", "img/img6.jpg", "img/img7.jpg", "img/img8.jpg", "img/img9.jpg", ]; for (var i = 0; i < imgs.length; i++) { var li = document.createElement("li"); var img = document.createElement("img"); img.src = imgs[i]; li.appendChild(img); ul.appendChild(li); } var lis = document.querySelectorAll("li"); window.onload = window.onresize = function() { for (var i = 0; i < lis.length; i++) { lis[i].style.width = (ul.offsetWidth / imgs.length) - 10 + "px"; } } var imgM = document.querySelectorAll("img"); for (let i = 0; i < imgM.length; i++) { imgM[i].onmouseenter = function() { for (var j = 0; j < imgM.length; j++) { lis[j].style.width = ((ul.offsetWidth - imgM[i].offsetWidth) / (imgs.length - 1)) - 10 + "px"; } lis[i].style.width = imgM[i].offsetWidth + "px"; } imgM[i].onmouseleave = function() { for (var i = 0; i < lis.length; i++) { lis[i].style.width = (ul.offsetWidth / imgs.length) - 10 + "px"; } } } </script> </body> </html> 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:
|
<<: Nginx server https configuration method example
>>: How to install MySQL 5.7.17 and set the encoding to utf8 in Windows
Pre-installation preparation The main purpose of ...
Docker supports running on the following CentOS v...
1. When designing a web page, determining the widt...
Table of contents JavaScript private class fields...
Table of contents 1. What is lazy loading? 2. Imp...
After I found that the previous article solved th...
1. Percentage basis for element width/height/padd...
Table of contents Previous words Synchronous and ...
As we all know, binlog logs are very important fo...
Preface If CSS is the basic skill of front-end de...
After the server where Docker is located has been...
Since Alibaba Cloud's import of custom Ubuntu...
Table of contents (I) Using Workbench to operate ...
Table of contents Preface: Detailed introduction:...
1. First, generate the public key and private key...