Skip to main content

Learn how to create a responsive slideshow with CSS and JavaScript.

Source code of Learn how to create a responsive slideshow with CSS and JavaScript.
presented by @webdev_coding
 
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="viewport" content="width=device-width, initial-scale=1">
  5. <style>
  6. * {box-sizing: border-box}
  7. body {font-family: Verdana, sans-serif; margin:0}
  8. .mySlides {display: none}
  9. img {vertical-align: middle;}

  10. /* Slideshow container */
  11. .slideshow-container {
  12.   max-width: 1000px;
  13.   position: relative;
  14.   margin: auto;
  15. }

  16. /* Next & previous buttons */
  17. .prev, .next {
  18.   cursor: pointer;
  19.   position: absolute;
  20.   top: 50%;
  21.   width: auto;
  22.   padding: 16px;
  23.   margin-top: -22px;
  24.   color: white;
  25.   font-weight: bold;
  26.   font-size: 18px;
  27.   transition: 0.6s ease;
  28.   border-radius: 0 3px 3px 0;
  29.   user-select: none;
  30. }

  31. /* Position the "next button" to the right */
  32. .next {
  33.   right: 0;
  34.   border-radius: 3px 0 0 3px;
  35. }

  36. /* On hover, add a black background color with a little bit see-through */
  37. .prev:hover, .next:hover {
  38.   background-color: rgba(0,0,0,0.8);
  39. }

  40. /* Caption text */
  41. .text {
  42.   color: #f2f2f2;
  43.   font-size: 15px;
  44.   padding: 8px 12px;
  45.   position: absolute;
  46.   bottom: 8px;
  47.   width: 100%;
  48.   text-align: center;
  49. }

  50. /* Number text (1/3 etc) */
  51. .numbertext {
  52.   color: #f2f2f2;
  53.   font-size: 12px;
  54.   padding: 8px 12px;
  55.   position: absolute;
  56.   top: 0;
  57. }

  58. /* The dots/bullets/indicators */
  59. .dot {
  60.   cursor: pointer;
  61.   height: 15px;
  62.   width: 15px;
  63.   margin: 0 2px;
  64.   background-color: #bbb;
  65.   border-radius: 50%;
  66.   display: inline-block;
  67.   transition: background-color 0.6s ease;
  68. }

  69. .active, .dot:hover {
  70.   background-color: #717171;
  71. }

  72. /* Fading animation */
  73. .fade {
  74.   -webkit-animation-name: fade;
  75.   -webkit-animation-duration: 1.5s;
  76.   animation-name: fade;
  77.   animation-duration: 1.5s;
  78. }

  79. @-webkit-keyframes fade {
  80.   from {opacity: .4} 
  81.   to {opacity: 1}
  82. }

  83. @keyframes fade {
  84.   from {opacity: .4} 
  85.   to {opacity: 1}
  86. }

  87. /* On smaller screens, decrease text size */
  88. @media only screen and (max-width: 300px) {
  89.   .prev, .next,.text {font-size: 11px}
  90. }
  91. </style>
  92. </head>
  93. <body>

  94. <div class="slideshow-container">

  95. <div class="mySlides fade">
  96.   <div class="numbertext">1 / 3</div>
  97.   <img src="img_nature_wide.jpg" style="width:100%">
  98.   <div class="text">Caption Text</div>
  99. </div>

  100. <div class="mySlides fade">
  101.   <div class="numbertext">2 / 3</div>
  102.   <img src="img_snow_wide.jpg" style="width:100%">
  103.   <div class="text">Caption Two</div>
  104. </div>

  105. <div class="mySlides fade">
  106.   <div class="numbertext">3 / 3</div>
  107.   <img src="img_mountains_wide.jpg" style="width:100%">
  108.   <div class="text">Caption Three</div>
  109. </div>

  110. <a class="prev" onclick="plusSlides(-1)">&#10094;</a>
  111. <a class="next" onclick="plusSlides(1)">&#10095;</a>

  112. </div>
  113. <br>

  114. <div style="text-align:center">
  115.   <span class="dot" onclick="currentSlide(1)"></span> 
  116.   <span class="dot" onclick="currentSlide(2)"></span> 
  117.   <span class="dot" onclick="currentSlide(3)"></span> 
  118. </div>

  119. <script>
  120. var slideIndex = 1;
  121. showSlides(slideIndex);

  122. function plusSlides(n) {
  123.   showSlides(slideIndex += n);
  124. }

  125. function currentSlide(n) {
  126.   showSlides(slideIndex = n);
  127. }

  128. function showSlides(n) {
  129.   var i;
  130.   var slides = document.getElementsByClassName("mySlides");
  131.   var dots = document.getElementsByClassName("dot");
  132.   if (n > slides.length) {slideIndex = 1}    
  133.   if (n < 1) {slideIndex = slides.length}
  134.   for (i = 0; i < slides.length; i++) {
  135.       slides[i].style.display = "none";  
  136.   }
  1.   for (i = 0; i < dots.length; i++) {
  2.       dots[i].className = dots[i].className.replace(" active", "");
  3.   }
  4.   slides[slideIndex-1].style.display = "block";  
  5.   dots[slideIndex-1].className += " active";
  6. }
  7. </script>

  8. </body>
  9. </html> 
Follow on :- @webdev_coding 

Download images : - 





Comments

Popular posts from this blog

HOW TO MAKE A WINDOW-10-LOGO USING HTML AND CSS

HOW TO MAKE A WINDOW-10-LOGO USING HTML AND CSS FOLLOW ON INSTAGRAM FOR MORE @CODING.BATCH CLICK TO DOWNLOAD

How to create a instagram logo using html & css

Learn How to create a instagram logo using html & css source code of How to create a instagram logo using html & css By :- coding.batch HTML CODE :-     <body>     <div class="logo"></div>     </body> css code :-       * {         padding: 0;         margin: 0;         box-sizing: border-box;     }     body {         height: 100vh;         width: 100vw;         display: flex;         justify-content: center;         align-items: center;     }  ...

NEON TEXT EFFECT USING HTML AND CSS

NEON TEXT EFFECT USING HTML AND  CSS FOLLOW ON INSTAGRAM FOR MORE  @CODING.BATCH CLICK TO DOWNLOAD