【问题标题】:css keyframe position issuecss关键帧位置问题
【发布时间】:2016-08-10 05:46:41
【问题描述】:

我想知道如何设置关键帧的分辨率大小,我的网站上有一个从上到下的气泡。我已经为我的屏幕尺寸正确设置了它,但我注意到当屏幕尺寸发生变化时,气泡会向下更多并创建空白空间。这绝对是因为我将它设置为 top:-500px 和 top:500px 所以在每个屏幕尺寸中它都采用 500px 作为固定高度。我想以这样的方式设置 top:500px ,只要大小发生变化,它就应该占据屏幕高度并且应该停在底部。 我尝试了一些代码但没有成功,请您检查一下:

.x4 {
    left: 1025px;
    -webkit-transform: scale(0.8);
    -moz-transform: scale(0.8);
    transform: scale(0.8);
    opacity: 0.3;
    width:315px;
  height:315px;
    -webkit-animation: moveclouds 15s linear forwards , sideWays 2s ease-in-out infinite alternate;
    -moz-animation: moveclouds 15s linear forwards , sideWays 2s ease-in-out infinite alternate;
    -o-animation: moveclouds 15s linear forwards , sideWays 2s ease-in-out infinite alternate;
      background-image: url(http://dubaiconfident.com/confi-logo/grey1-bubble.png);
}

@-webkit-keyframes moveclouds {
    0% {
        top: -500px;
    }
   100% {
        top: 500px;
    }
} 

【问题讨论】:

标签: html css resolution screen-size keyframe


【解决方案1】:

使用带有position:fixedtop 属性的移动元素,以百分比 作为单位而不是像素(因此,开始位置0%,结束100%-height of element ) .当然,您的元素的父级必须是 body


如果您想更好地控制 css 关键帧,请将它们设置为响应式、动态生成和重新生成它们,请使用类似 jQuery.Keyframes 的工具

【讨论】:

  • 不,它没有帮助我做到了@-webkit-keyframes moveclouds { 0% { top: 0%; } 100% { 顶部:100%; } } 这需要泡沫,我不知道底部在哪里:(
  • 不是完整的 100% 顶部;它会将您的元素推到视口的底部边缘,尝试使用更少的百分比。
  • 你可以使用-100%甚至-200%
  • 我尝试将其设为 -64%,但将其作为特定高度 @-webkit-keyframes moveclouds { 0% { top: -100%; } 100% { 最高: 64%; } }
  • 然后在调整屏幕大小时再次改变位置
【解决方案2】:

尝试以下代码并使用media query 使其在其他屏幕分辨率下正常工作,您可以使用vh (viewport height)% (percentage) 设置该气泡的着陆或停止。

.x4 {
    -webkit-transform: scale(0.8);
    -moz-transform: scale(0.8);
    transform: scale(0.8);
    opacity: 0.3;
    left:calc(100% - 75%);
    -webkit-animation: moveclouds 5s linear forwards;
    -moz-animation: moveclouds 5s;
    -o-animation: moveclouds 5s;
      background-image: url(http://dubaiconfident.com/confi-logo/grey1-bubble.png);
      background-size:100% 100%;
      background-repeat:no-repeat;
      position:relative;
      width:320px;
      height:320px;
}

@-webkit-keyframes moveclouds {
    0%{
        top: -50vh;
    }
   100% {
        top: 30vh;
    }
} 

@media screen and (max-width: 480px){
.x4 {
    left:calc(100% - 70%);
      width:200px;
      height:200px;
}

@-webkit-keyframes moveclouds {
    0%{
        top: -50vh;
    }
   100% {
        top: 30vh;
    }
}  
}
<div class="x4">

</div>

【讨论】:

  • No Not working 气泡到底部并创建空白区域,然后气泡消散器 :(
  • @NS123 它停在页面的中心,这就是为什么它下面的所有东西都是空白,你想要它在哪里并且它不会消失。根据您的计划将关键帧动画 100% 最高值从 30vh 更改为 60 或 100vh。
  • 它应该停在页面底部。并且无论屏幕尺寸如何,它都应该停在底部。
猜你喜欢
  • 2015-05-23
  • 2015-12-25
  • 1970-01-01
  • 1970-01-01
  • 2018-12-18
  • 2020-12-23
  • 2012-01-09
  • 2015-11-28
  • 2014-04-04
相关资源
最近更新 更多