2017-03-10 66 views
0

即时通讯试图为我的网站上的图像应用“震撼”动画。问题是,脚本扩展了宽度,所以我可以看到我的浏览器的底部栏:CSS动画,职位

HTML:

<div class="wrapper"> 
     <article class="top-logo"> 
      <h1> 
       <a href="#" target="_blank"><img src="img/logo.png" alt="robbie-logo"></a> 
      </h1> 
     </article> 

CSS:

.top-logo { 
    position: relative; 
    float: right; 
} 
.top-logo img { 
    height: 150px; 
    width: 350px; 
    -webkit-transform-style: preserve-3d; 
} 

.top-logo:hover { 
    animation-name: diagonal-slide; 
    animation-duration: 0.05s; 
    animation-iteration-count: 10; 
    animation-fill-mode: forwards; 
} 

@-webkit-keyframes diagonal-slide { 
    from { top: 0; left: 0; animation-timing-function: linear; } 
    20% { top: -5px; left: -5px; animation-timing-function: linear; } 
    40% { top: 5px; left: -5px; animation-timing-function: linear; } 
    60% { top: 5px; left: 5px; animation-timing-function: linear; } 
    80% { top: -5px; left: 5px; animation-timing-function: linear; } 
    to { top: 0; left: 0; animation-timing-function: linear; } 
} 
+0

很高兴看到更完整的HTML/CSS,因此可以重新创建问题。 – rasmeister

+1

溢出:隐藏;在这里完成了这项工作/关闭 – robertbie

回答

1

它不会发生在这里(没有滚动条),但仍然,尽量把它添加到容器:

.wrapper { 
    overflow: hidden; 
} 

.wrapper { 
 
    overflow: hidden; 
 
} 
 

 
.top-logo { 
 
    position: relative; 
 
    float: right; 
 
} 
 

 
.top-logo img { 
 
    height: 150px; 
 
    width: 350px; 
 
    -webkit-transform-style: preserve-3d; 
 
} 
 

 
.top-logo:hover { 
 
    animation-name: diagonal-slide; 
 
    animation-duration: 0.05s; 
 
    animation-iteration-count: 10; 
 
    animation-fill-mode: forwards; 
 
} 
 

 
@-webkit-keyframes diagonal-slide { 
 
    from { 
 
    top: 0; 
 
    left: 0; 
 
    animation-timing-function: linear; 
 
    } 
 
    20% { 
 
    top: -5px; 
 
    left: -5px; 
 
    animation-timing-function: linear; 
 
    } 
 
    40% { 
 
    top: 5px; 
 
    left: -5px; 
 
    animation-timing-function: linear; 
 
    } 
 
    60% { 
 
    top: 5px; 
 
    left: 5px; 
 
    animation-timing-function: linear; 
 
    } 
 
    80% { 
 
    top: -5px; 
 
    left: 5px; 
 
    animation-timing-function: linear; 
 
    } 
 
    to { 
 
    top: 0; 
 
    left: 0; 
 
    animation-timing-function: linear; 
 
    } 
 
}
<div class="wrapper"> 
 
    <article class="top-logo"> 
 
    <h1> 
 
     <a href="#" target="_blank"><img src="http://placehold.it/100x60/fa0" alt="robbie-logo"></a> 
 
    </h1> 
 
    </article> 
 
</div>

+0

你能否详细说明OP为什么要考虑这样做?额外的CSS在这种情况下做了什么? – rasmeister

+0

谢谢,溢出:隐藏;是交易:) – robertbie

+1

当动画被触发时,他会谈到关于obvioulsy的滚动条,延长窗口的右边界。通过试图隐藏任何溢出,我试图阻止这种情况。 – Johannes