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
# Adjust VMware hard disk boot priority Step 1: E...
The question is referenced from: https://www.zhih...
MySQL implements Oracle-like sequences Oracle gen...
1. Software Download MySQL download and installat...
Purpose: Under Linux, the server program may be d...
Generally, on national days of mourning, days of ...
In front-end projects, attachment uploading is a ...
VMWare (Virtual Machine ware) is a "virtual ...
Table of contents One-way data flow explanation V...
Table of contents 1. Check whether MySQL has been...
1. Function : Allows the parent component to inse...
Preface: Due to my work, I am involved in the fie...
This article example shares the specific code for...
1. Create a project with vue ui 2. Select basic c...
There was an article about the execution process ...