Advertisement
1xptolevitico69

Amazing CSS Carousel with indicators

Dec 31st, 2021
1,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.53 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>Amazing CSS Carousel with indicators</title>
  9.   <style>
  10.     #bt_left {
  11.       position: absolute;
  12.       top: 200px;
  13.       left: -50px;
  14.       transform: rotateY(0deg);
  15.       width: 30px;
  16.       cursor: pointer;
  17.     }
  18.  
  19.     #bt_right {
  20.       transform: rotateY(180deg);
  21.       position: absolute;
  22.       top: 200px;
  23.       right: -50px;
  24.       width: 30px;
  25.       cursor: pointer;
  26.     }
  27.  
  28.     #box {
  29.       width: 800px;
  30.       height: 500px;
  31.       position: absolute;
  32.       left: 50%;
  33.       transform: translate(-50%);
  34.       top: 10px;
  35.     }
  36.  
  37.     #container {
  38.       width: 800px;
  39.       height: 500px;
  40.       overflow: hidden;
  41.       border: 5px solid maroon;
  42.     }
  43.  
  44.     .car {
  45.       width: 800px;
  46.       height: 500px;
  47.     }
  48.  
  49.     #carousel {
  50.       display: flex;
  51.     }
  52.  
  53. .clone{
  54. position:absolute;
  55. top:0;
  56. right:0;
  57. }
  58.  
  59. .clone img{
  60. width:200px;
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.   </style>
  68. </head>
  69.  
  70. <body>
  71.  
  72.   <div id='box'>
  73.  
  74.     <img id='bt_left' onclick='sliderLeft()' src='https://1xpto.netlify.app/icons/left.png' />
  75.     <img id='bt_right' onclick='sliderRight()' src='https://1xpto.netlify.app/icons/left.png' />
  76.  
  77.     <div id='container'>
  78.  
  79.       <div id='carousel'>
  80.         <img class='car' src='https://1xpto.netlify.app/pics/1.jpg' />
  81.         <img class='car' src='https://1xpto.netlify.app/pics/3.jpg' />
  82.         <img class='car' src='https://1xpto.netlify.app/pics/4.jpg' />
  83.         <img class='car' src='https://1xpto.netlify.app/pics/7.jpg' />
  84.         <img class='car' src='https://1xpto.netlify.app/pics/car.jpeg' />
  85.  
  86.       </div>
  87.     </div>
  88.   </div>
  89.  
  90.     <a class='clone' href='https://www.youtube.com/channel/UCqLpDK0eOsG1eEeF9jOUZkw'><img src='https://1xpto.netlify.app/pics/clone.png'/></a>
  91.  
  92.  
  93.  
  94.  
  95.  
  96.   <script>
  97.     a = 0;
  98.     i = 0;
  99.     b = 0;
  100.     car = document.getElementsByClassName('car');
  101.  
  102.     function sliderLeft() {
  103.       if (a == car.length - 1) {
  104.         i = i + 0;
  105.         carousel.style.marginLeft = i + 'px';
  106.       } else {
  107.         i = i - 800;
  108.         a++;
  109.         b--;
  110.         carousel.style.marginLeft = i + 'px';
  111.       }
  112.     }
  113.  
  114.     function sliderRight() {
  115.       if (b == 0) {
  116.         i = i + 0;
  117.         carousel.style.marginLeft = i + 'px';
  118.       } else {
  119.         i = i + 800;
  120.         b++;
  121.         a--;
  122.         carousel.style.marginLeft = i + 'px';
  123.       }
  124.     }
  125.   </script>
  126. </body>
  127. </htm>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement