0

所以我想将鼠标悬停在一个 Box 上并让它激活另一个具有缓动效果的 div。您可以看到下面.images{}有一个 0s 无限滚动,然后.box:hover > .images{}是当我将 0s 更改为 10s 以开始幻灯片放映时。

HTML

<div class="slideshow">
     <div class="images"></div>
     <div class="box"></div>   
</div>

CSS:

.slideshow {
  position: relative;
  overflow: hidden;
  height: 220px;
  width: 100%;
}
.box {
width:100px;
height:100px;
position: absolute;
left: 0;
top: 0;
background-color: #333;
}

.images {
  background: url('http://jamesebeling.com/testing/jamesebeling/wp-content/uploads/2013/08/buildings.png');
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 300%;
 -webkit-transition: all 1s ease-out;
  -moz-transition: all 1s ease-out;
  -o-transition: all 1s ease-out;
  transition: all 1s ease-out;
  -webkit-animation: slideshow 0s linear infinite;
  -moz-animation:    slideshow 0s linear infinite;
}
@-webkit-keyframes slideshow {
  0%    { left: 0; }
  100%  { left: -200%; }
}
@moz-keyframes slideshow {
  0%    { left: 0; }
  100%  { left: -200%; }
}
/* Hey browser, use your GPU */
   -webkit-transform: translate3d(0, 0, 0);
}

@-webkit-keyframes moveSlideshow {
    0%   { 
        -webkit-transform: translateX(0);  
    }    
    100% { 
        -webkit-transform: translateX(-200%);  
    }
}
@-moz-keyframes moveSlideshow {
    0%   { 
        -moz-transform:    translateX(0); 
    }    
    100% { 
        -moz-transform:    translateX(-200%); 
    }
}

.box:hover > .images {
.images {
  background: url('http://jamesebeling.com/testing/jamesebeling/wp-content/uploads/2013/08/buildings.png');
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 300%;
 -webkit-transition: all 1s ease-out;
  -moz-transition: all 1s ease-out;
  -o-transition: all 1s ease-out;
  transition: all 1s ease-out;
  -webkit-animation: slideshow 10s linear infinite;
  -moz-animation:    slideshow 10s linear infinite;
}
@-webkit-keyframes slideshow {
  0%    { left: 0; }
  100%  { left: -200%; }
}
@moz-keyframes slideshow {
  0%    { left: 0; }
  100%  { left: -200%; }
}
/* Hey browser, use your GPU */
   -webkit-transform: translate3d(0, 0, 0);
}

@-webkit-keyframes moveSlideshow {
    0%   { 
        -webkit-transform: translateX(0);  
    }    
    100% { 
        -webkit-transform: translateX(-200%);  
    }
}
@-moz-keyframes moveSlideshow {
    0%   { 
        -moz-transform:    translateX(0); 
    }    
    100% { 
        -moz-transform:    translateX(-200%); 
    }
}
4

1 回答 1

1

如果您将 HTML 更改为在box类之前包含images类,则可以使用相邻的选择器来选择.images它的前面是否为.box:hover

.box:hover + .images { ... }

工作演示

我还添加z-index: 1了它,.box所以它位于图像元素的顶部。

于 2013-08-12T18:04:04.343 回答