简体   繁体   English

我想在我的网站上添加幻灯片。 我正在使用html,css,并希望使用jquery。 如何创建响应式图像幻灯片

[英]I want to add a slideshow to my website. I'm using html, css, and want to use jquery. How can I create a responsive image slideshow

This is what I have so far. 这就是我到目前为止所拥有的。 I'm able to keep the images in container but the arrows aren't working. 我能够将图像保存在容器中,但箭头不起作用。

I need help with the Jquery part and making the images run cycle by themselves but also allow arrows to be clicked to change the images. 我需要帮助Jquery部分并使图像自己循环运行,但也允许点击箭头来更改图像。

  /*HEADER SECTION allwork*/ #container { width: 1200px; height: 628px; border: 0px solid black; margin: 0 auto; position: relative; } #container>img { width: 100% height: 100%; position: absolute; #container>.btn1 { position: absolute; width: 50px; height: 50px; border: none; border-radius: 15px; top: 150px; background: #2ecc71; color: white; font-size: 30px; } #container>#btn1:hover { box-shadow: 10px 0px 20px 0px #2ecc71; } #container>#btn1:hover { box-shadow: 10px 0px 20px 0px #2ecc71; } #container>#btn1 { position: relative; float: right; } 
 <!DOCTYPE html> <html lang="en"> <head> <meta name 'viewport' content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="HandheldFriendly" content="true"> <meta Charset='uft-8'> <link rel='shortcut icon' href="images/favicon.png"> <link rel="stylesheet" href="index.css"> </head> <body> <div id="head"> <div class="header"> <img class="logo" src="images/LOGO.png" alt="logo" /> <ul> <li><a class="navbar" href="index.hmtl">About</a></li> <li><a class="navbar" href="resume.hmtl">Resume</a></li> <li><a class="navbar" href="all work.hmtl">All Work</a></li> </ul> </div> </div> <div id="container"> <img class="slides" src="images/overview.png"> <img class="slides" src="images/construction.png"> <button class="btn1" onclick="plusDivs(-1)">&#10094;</button> <button class="btn2" onclick="plusDivs(+1)">&#10095;</button> </div> <script src="jquery.js"></script> <script src="script.js"></script> </body> </html> 

I would suggest you to go through the link 我建议你仔细阅读链接

https://www.w3schools.com/howto/howto_js_slideshow.asp

The slideshow is ideally known as Carousel. 幻灯片显然被称为Carousel。 You can also look into bootstrap framework which has in built carousel support 您还可以查看具有内置轮播支持的bootstrap框架

https://www.w3schools.com/bootstrap/bootstrap_carousel.asp

Here is the javascript code : 这是javascript代码:

<script>
    var slideIndex = 1;
    showDivs(slideIndex);

    function plusDivs(n) {
        showDivs(slideIndex += n);
     }

    function showDivs(n) {
      var i;
      var x = document.getElementsByClassName("slides");
      if (n > x.length) {slideIndex = 1}    
      if (n < 1) {slideIndex = x.length}
      for (i = 0; i < x.length; i++) {
      x[i].style.display = "none";  
      }
     x[slideIndex-1].style.display = "block";  
   }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM