javascript - 如何在 CSS 中同时淡入淡出

标签 javascript jquery html css

body {
  background-image: url("back.jpg");
  background-attachment: fixed;
  font-family: 'Open Sans', serif;
  color: white;
}
#container {
  height: 1000px;
}
/* HEADER WITH NAV BAR AND LOGIN SNIPPET */
#head {
  position: absolute;
  height: 150px;
  width: 100%;
  background-color: #ffffff;
  right: 0px;
  left: 0px;
  top: 0px;
}

#logo-image {
  position: relative;
  margin-top: 40px;
  margin-left: 40px;
}

#logo-image:hover {
  -webkit-animation: blur 0.5s ease-in;
}

@-webkit-keyframes blur {
  0% {
    -webkit-filter: blur(0px);
    filter: blur(0px);
  }
  50% {
    -webkit-filter: blur(1px);
    filter: blur(2px);
  }
  100% {
    -webkit-filter: blur(0px);
    filter: blur(0px);
  }
}

.navbar-fixed {
  top: 0;
  z-index: 100;
  position: fixed;
  width: 100%;
}

.navigationmenu-main {
  list-style-type: none;
  overflow: hidden;
  background-color: #333;
}

.navigationmenu-parent {
  float: left;
}

.navigationmenu-child {
  display: inline-block;
  color: white;
  width: 50px;
  text-align: center;
  padding: 10px 16px;
  text-decoration: none;
  background-color: #333;
  -webkit-transition: background-color .3s;
}

.navigationmenu-child:hover {
  background-color: #111;
}

.navigationmenu-child:hover + .navigationmenu-line {
  width: 100%;
}

.navigationmenu-line {
  height: 3px;
  background-color: red;
  width: 0%;
  -webkit-transition: width .3s;
  -webkit-transition-timing-function: ease;
}

.login-parent {
  float: right;
}

.login-child {
  display: inline-block;
  color: white;
  width: auto;
  text-align: center;
  padding: 10px 16px;
  text-decoration: none;
  background-color: #333;
  -webkit-transition: background-color .3s;
}

.login-child:hover {
  background-color: #111;
}

.login-child:hover + .navigationmenu-line {
  width: 100%;
}

#loginbox {
  display: block;
  visibility: hidden;
  position: absolute;
  top: 132px;
  right: 90px;
  z-index: 999;
  background: #a6a6a6;
  background-image: linear-gradient(top, #fff, #eee);
  padding: 15px;
  box-shadow: 0 2px 2px -1px rgba(0, 0, 0, .9);
  border-radius: 3px 0 3px 3px;
  -webkit-transition: padding .3s;
}

.login-parent:hover #loginbox {
  visibility: visible;
}

#loginform {
  padding: 5px;
}

#loginelement {
  padding: 5px;
}
/*----------------------*/
/* MAIN BODY */
#main{
	position: relative;
  height: 100%;
  width: 90%;
  margin-left: auto;
  margin-right: auto;
  background-color: #ffffff;
  top: 0px;
  bottom: 100px;
}
#box {
  position: relative;
  height: 100%;
  width: 90%;
  margin-left: auto;
  margin-right: auto;
  background-color: rgba(255,255,255,0.4);
  top: 140px;
  bottom: 100px;
  box-shadow: 4px 4px 3px 1px rgba(0,0,0,0.4);
}
/*---------------*/
/* SLIDER */
.slider {
  max-width: 100%;
  height: 500px;
  margin: 20px auto;
  position: absolute;
  top: 130px;
  left: 0px;
  right: 0px;
}
.slide1,.slide2,.slide3,.slide4,.slide5 {
  position: absolute;
  width: 100%;
  height: 100%;
}
.slide1 {
  background: url("1.jpg")no-repeat center;
      background-size: cover;
    animation:fade 8s infinite;
-webkit-animation:fade 8s infinite;
} 
.slide2 {
  background: url("2.jpeg")no-repeat center;
      background-size: cover;
    animation:fade2 8s infinite;
-webkit-animation:fade2 8s infinite;
}
.slide3 {
    background: url("3.jpg")no-repeat center;
      background-size: cover;
    animation:fade3 8s infinite;
-webkit-animation:fade3 8s infinite;
}
@keyframes fade
{
  0%   {opacity:1}

  33.333% { opacity: 0}
  66.666% { opacity: 0}
  100% { opacity: 1}
}
@keyframes fade2
{
  0%   {opacity:0}
  33.333% { opacity: 1}
  66.666% { opacity: 0 }
  100% { opacity: 0}
}
@keyframes fade3
{
  0%   {opacity:0}
  33.333% { opacity: 0}
  66.666% { opacity: 1}
  100% { opacity: 0}
}
/*-----------------*/
/* FOOT AREA FIXED */
#foot {
  position: fixed;
  height: 80px;
  width: 100%;
  background-color: #333;
  right: 0px;
  left: 0px;
  bottom: 0px;
}
<!DOCTYPE html>
<html>

  <head>
    <title>
      Le Meridian | A home away from home
    </title>
    <link rel="stylesheet" type="text/css" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
  </head>
  <!DOCTYPE html>
  <title>
    Le Meridian | A home away from home
  </title>

  <body>
    <div id="container">
      <div id="head">
        <img src="logo.png" id="logo-image" height="20%" width="20%">
        <ul id="nav_bar" class="navigationmenu-main">
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">A</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">B</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">C</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">D</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">E</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">F</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="navigationmenu-parent">
            <a href="" class="navigationmenu-child">G</a>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="login-parent">
            <div class="login-child">Sign Up</div>
            <div class="navigationmenu-line">
            </div>
          </li>
          <li class="login-parent">
            <div class="login-child" id="trigger">Login ▼</div>
            <div class="navigationmenu-line">
            </div>
            <div id="loginbox">
              <form id="loginform">
                <input type="text" name="email" id="loginelement" placeholder="UserId / email">
                <br>
                <br>
                <input type="password" name="password" id="loginelement" placeholder="Password">
                <br>
                <br>
                <input type="submit" name="loginsubmit" id="loginelement">
                <input type="checkbox" name="loggedin" id="loginelement"> Stay Signed In
              </form>
            </div>
          </li>
        </ul>
      </div>
      <div class='slider'>
			  <div class='slide1'></div>
			  <div class='slide2'></div>
			  <div class='slide3'></div>
			</div>
        	
      <div id="foot">
        <p align="Center">
          Windsor Place, New Delhi, New Delhi, 110001, India
        </p>
      </div>
    </div>
  </body>

</html>

我正在制作一个 CSS 图像幻灯片,但我无法让 pic 1 淡出和 pic 2 淡入淡出 both in 1 animation..please help 我希望淡入淡出平滑,即第一张图片的淡出应该恰好从第二张图片的淡入开始

最佳答案

我认为你不需要为不同的背景使用多个幻灯片 div,只使用一个

<div class="slider">
    <div class="slide1"></div>
</div>

和CSS

.slide1 {
   position: absolute;
   width: 300px;
   height: 200px;
   background: url("https://unsplash.it/200/300") no-repeat center;
   background-size: cover;
   animation:fade 8s infinite;
   -webkit-animation:fade 8s infinite;
} 

@keyframes fade {
   0%   {
     background: url("1.jpg") no-repeat center;
   }
   33.333% {
      background: url("2.jpg") no-repeat center;
   }
   66.666% {
      background: url("3.jpg") no-repeat center;
   }
   100% {
      background: url("1.jpg") no-repeat center;
   }
}

关于javascript - 如何在 CSS 中同时淡入淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42905155/

相关文章:

javascript - 我怎样才能重用功能而不是不断重复它?

javascript - 如何在 D3 设计中添加悬停文本?

javascript - 如何查找三维数组的索引

javascript - 确定 Javascript 选择 'change' 事件是由用户还是通过代码执行的?

javascript - 如何在Javascript中选择第n张图片

javascript - 使用 jQuery 或 Javascript 重定向到带有值的给定页面

javascript - 设置每个图像在不同时间的间隔

html - 防止div高度为 "0"

jquery - 如何将 Tab 键限制为页面上的特定形式或一组链接/按钮?

html - 页脚问题后的空白