├── img ├── 1.jpg ├── 2.jpg ├── 3.jpg ├── 4.jpg └── 5.jpg ├── project.png ├── README.md ├── app.js ├── index.html └── style.css /img/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HoanghoDev/slider_dots/HEAD/img/1.jpg -------------------------------------------------------------------------------- /img/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HoanghoDev/slider_dots/HEAD/img/2.jpg -------------------------------------------------------------------------------- /img/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HoanghoDev/slider_dots/HEAD/img/3.jpg -------------------------------------------------------------------------------- /img/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HoanghoDev/slider_dots/HEAD/img/4.jpg -------------------------------------------------------------------------------- /img/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HoanghoDev/slider_dots/HEAD/img/5.jpg -------------------------------------------------------------------------------- /project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HoanghoDev/slider_dots/HEAD/project.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Youtube Lun Dev 3 | 4 | Free code HTML CSS Javascript and Free learning web developer 5 | 6 | 7 |  8 | 9 | ## Image in project 10 | 11 |  12 | - [Detailed instructions on this project](https://www.youtube.com/@lundeveloper/featured) 13 | 14 | 15 | ## Follow me for more free codes 16 | 17 | - [Youtube Lun Dev](https://www.youtube.com/results?search_query=lun+dev) 18 | - [Tiktok Lun Dev](https://www.tiktok.com/@lun.dev) 19 | - [Website Lun Dev Web](https://lundevweb.com) 20 | 21 | 22 | ## Built By 23 | 24 | This project is built and shared by 25 | 26 | - Lun Dev Youtube 27 | 28 | 29 | ## Feedback 30 | 31 | If you have any feedback, please reach out to us at hohoang.dev@gmail.com 32 | 33 | 34 | ## Tags 35 | 36 | Free code HTML CSS Javascript and Free learning web developer, html code, css code, javascript code tutorial 37 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | let slider = document.querySelector('.slider .list'); 2 | let items = document.querySelectorAll('.slider .list .item'); 3 | let next = document.getElementById('next'); 4 | let prev = document.getElementById('prev'); 5 | let dots = document.querySelectorAll('.slider .dots li'); 6 | 7 | let lengthItems = items.length - 1; 8 | let active = 0; 9 | next.onclick = function(){ 10 | active = active + 1 <= lengthItems ? active + 1 : 0; 11 | reloadSlider(); 12 | } 13 | prev.onclick = function(){ 14 | active = active - 1 >= 0 ? active - 1 : lengthItems; 15 | reloadSlider(); 16 | } 17 | let refreshInterval = setInterval(()=> {next.click()}, 3000); 18 | function reloadSlider(){ 19 | slider.style.left = -items[active].offsetLeft + 'px'; 20 | // 21 | let last_active_dot = document.querySelector('.slider .dots li.active'); 22 | last_active_dot.classList.remove('active'); 23 | dots[active].classList.add('active'); 24 | 25 | clearInterval(refreshInterval); 26 | refreshInterval = setInterval(()=> {next.click()}, 3000); 27 | 28 | 29 | } 30 | 31 | dots.forEach((li, key) => { 32 | li.addEventListener('click', ()=>{ 33 | active = key; 34 | reloadSlider(); 35 | }) 36 | }) 37 | window.onresize = function(event) { 38 | reloadSlider(); 39 | }; 40 | 41 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |