This article uses javascript+CSS to implement the specific code of the carousel effect for your reference. The specific content is as follows 1.html <ul id="banner" ></ul> 2.css ul{ list-style:none; position: absolute; padding: 0; left: 0; right: 0; bottom: 0; top:0; margin:auto; width: 800px; height:200px; } 3.js //Generate a carousel export function generateBanner(){ let sz = new Array(); let cur_ul = document.getElementById('banner'); const recommends = this.recommends; let timer = setInterval(getNextLi, 3000); //Generate the carousel image li for (let i = 0; i < recommends.length; i++) { //Generate tags let cur_li = document.createElement("li"); let cur_img = document.createElement("img"); //Add attributes cur_img.src = recommends[i].pic; //Add style cur_li.style.position = 'absolute'; cur_li.style.left = '0px'; cur_li.style.transitionDuration = '0.4s'; cur_li.style.cursor="pointer"; //ul total width 800, showing one complete 400px and two incomplete 200px cur_img.style.width = '125px'; cur_img.style.height = "100px"; //Append child element cur_li.appendChild(cur_img); cur_ul.appendChild(cur_li); //Put all into array for easy operation sz.push(cur_li); } //Generate two icons generateAngleIcons(); //Use the last three pictures to display let len = sz.length - 1; //The third from the last showThreeLi(); //Get the next li display and put the first one at the end of the array function getNextLi() { const li = sz[0]; sz = sz.slice(1); sz.push(li); //All li are restored for (let i = 0; i < sz.length; i++) { //All li are restored to their original size sz[i].style.transform = "scale(1)"; sz[i].style.left = "0px"; //li covers from small to large sz[i].style.zIndex = i; //Hide all sz[i].style.display = "none"; } //Show the last three pictures showThreeLi(); } //Show the last three pictures function showThreeLi() { sz[len - 2].style.left = "0px"; //The second to last picture sz[len - 1].style.left = "120px"; sz[len - 1].style.zIndex = 100; sz[len - 1].style.transform = "scale(1.3)"; //The last one sz[len].style.left = "230px"; //Display sz[len - 2].style.display = "block"; sz[len - 1].style.display = "block"; sz[len].style.display = "block"; } function generateAngleIcons(){ const icons = new Array(); for (let i = 0; i < 2; i++) { //Generate icon li let cur_li = document.createElement("li"); //Add style cur_li.style.position = 'absolute'; cur_li.style.top = '0px'; cur_li.style.bottom = '0px'; cur_li.style.margin = "auto"; cur_li.style.paddingTop="100px"; cur_li.style.paddingBottom="100px"; cur_li.style.zIndex = 20; icons.push(cur_li); } icons[0].style.left = '0px'; icons[1].style.right = '0px'; icons[0].innerHTML = '<i class="angle left icon"></i>' icons[1].innerHTML = '<i class="angle right icon"></i>' cur_ul.appendChild(icons[1]); cur_ul.appendChild(icons[0]); } } 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 Install Oracle Java 14 on Ubuntu Linux
>>: MySQL trigger trigger add, delete, modify and query operation example
1. Use the df command to view the overall disk us...
Introduction In orm frameworks, such as hibernate...
The previous blog post talked about the Registry ...
Table of contents question extend Solving the pro...
The so-called three-column adaptive layout means ...
Table of contents 1. Understanding Databases 1.1 ...
1. Check the software installation path: There is...
Preface In many cases, we will use virtual machin...
Table of contents 1. What is reflection? 2. Refle...
Effect html <body> <div class="cont...
Table of contents 1. Concept of array flattening ...
1. Download 4 rpm packages mysql-community-client...
RPM package management A packaging and installati...
How to configure custom path aliases in Vue In ou...
<br />This section introduces how to impleme...