褪色的图像网页设计


<!DOCTYPE html>
<html lang="en-US">
<head>
<style>

body {
    background-image: url("bg.jpg");

}
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
ul {
    list-style-type: none;
    padding: 0;
    overflow: hidden;
    background-color:  #000000;
    margin-left:100px;
}
li {
    float:left;

}
li a {
    display: block;
    color: white;
    text-align: left;
    padding: 14px 16px;
    text-decoration: none;

}
li a:hover {
    background-color:  #000000;
}

img {
    position: absolute;
   margin-top:10px;
    border: 1px solid #ccc;

}

img img {
    width: 100%;
    height: auto;

}
            img:nth-of-type(2){
                 -webkit-animation: fadeInOut 15s linear 5s infinite;
            }
            img:nth-of-type(3){
                 -webkit-animation: fadeInOut 15s linear 5s infinite;
            }
            img:nth-of-type(4){
                 -webkit-animation: fadeInOut 15s linear 5s infinite;
            }
            img:nth-of-type(5){
                 -webkit-animation: fadeInOut 15s linear 5s infinite;
            }


            @-webkit-keyframes fadeInOut{
            0% { opacity:1; } 
            17% { opacity:1; } 
            25% { opacity:0; } 
            92% { opacity:0; } 
            100% { opacity:1; }
            }
.image-wrapper {
  position: relative;
  height: 600px; // change to whatever works for you 
}
.image {
  position: absolute;
  top: 50%;
  border: 1px solid #ccc;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
}
.container { width: 1000px; }
.logo { 
  float: left; 
  width: 100px;
  height: 50px;
}
.nav { 
  float: right; 
  width: 880px;
}

</style>
<title>Badass Burgers</title>
</head>
<body style="height:1500px">


  <img class="logo" src='logo.jpg'/>
<div class="container">

  <ul class="nav">
  <li><a class="active" href="homepage.php">Home</a></li>
    <li><a href="info.php">About</a></li>
  <li><a href="about.php">Team</a></li>
  <li><a href="Menu.php">Menu</a></li>
  <li><a href="book.php">Book A Table</a></li>
  <li><a href="message.php">Message Us</a></li>
</ul>
  <div style="clear: both"></div>
</div>
 <div class="image-wrapper">
    <img class="image" src='food1.jpg' width="1400" height="600" />
    <img class="image" src='Food2.jpg' width="1400" height="600" />
    <img class="image" src='Food3.jpg' width="1400" height="600" />
    <img class="image" src='Food4.jpg' width="1400" height="600" />
</div>
</body>
</html>

嗨,我正在尝试在这 4 张网站图像之间淡入淡出。 到目前为止 太好了,但是我试图更改此代码。有谁知道如何 更改代码,以便每个图像在 5 秒后更改? 任何帮助都非常感激

正如 litel 所说,引导轮播非常适合您的示例。W3 学校在这里有一个关于 Bootstrap 的很好的教程,这是我用来构建我的第一个轮播的教程。

但是为了在你现在的上下文中回答你的问题,我认为用一个简短的脚本而不是CSS动画来做到这一点要容易得多。我将以下代码添加到文档的末尾,这似乎可以满足您的要求。希望有帮助。

<style>
.image-wrapper .image{
    display: none; /*Hide the images to begin with*/
}
</style>
<script>
var currentImage = 0;
$(document).ready(function(){
imageChanger(); /*First image fades in on page ready*/
setInterval(imageChanger, 5000);}); /*set a timer of 5000ms for each subsequent image*/
function imageChanger(){
    $('.image-wrapper img').eq(currentImage).fadeOut();
    currentImage = (currentImage+1)%4;
    $('.image-wrapper img').eq(currentImage).fadeIn();
}
</script>