【问题标题】:Overflow-X: hidden doesn't work with animation [duplicate]溢出-X:隐藏不适用于动画[重复]
【发布时间】:2017-02-23 17:56:20
【问题描述】:

我正在开发一个使用 CSS3 包含动画元素的网站。我遇到的一个问题是垂直滚动条。所以有一个元素不断地左右滑动:

@keyframes waves {
  0% {left:-50px;}
  50% {left: 0px;}
  100% {left: -50px;}
}

因此,对象大于屏幕尺寸。现在当然会出现垂直滚动条。我该如何隐藏它?

我将元素放在一个容器中,在那里我定义了overflow-x: hidden,但不知何故它不起作用。也许我只是做错了?我应该使用什么方法?

这是小提琴: https://jsfiddle.net/hsdoy3t4/

非常感谢您的帮助。

【问题讨论】:

    标签: html css animation


    【解决方案1】:

    因为它采用body标签的默认边距。

    为body标签设置margin:0

    body{
      margin:0;
    }
    #home {
    	width: 100vw;
    	overflow-x: hidden;
    }
    
    #object {
    	background-image: url('http://www.1000skies.com/800trim.jpg');
    	width: calc(100% + 50px);
    	height: 158px;
      position: relative;
    	-webkit-animation: waves 2s infinite;
        -moz-animation: waves 2s infinite;
        animation: waves 2s infinite;
    }
    
    @-webkit-keyframes waves {
      0% {left:-50px;}
      50% {left: 0px;}
      100% {left: -50px;}
    }
    
    @-moz-keyframes waves {
      0% {left:-50px;}
      50% {left: 0px;}
      100% {left: -50px;}
    }
    
    @keyframes waves {
      0% {left:-50px;}
      50% {left: 0px;}
      100% {left: -50px;}
    }
    <section id="home">
      <div id="object"></div>
    </section>

    【讨论】:

      猜你喜欢
      • 2012-01-20
      • 2014-02-28
      • 2018-10-04
      • 2013-12-16
      • 2020-03-28
      • 1970-01-01
      • 2022-08-24
      • 2020-03-02
      相关资源
      最近更新 更多