【问题标题】:Expanding circles with css3 animation pixelating on larger viewports在较大的视口上使用 css3 动画像素化扩展圆圈
【发布时间】:2017-01-13 14:26:14
【问题描述】:

我有一个半径为 10 像素并扩大到 100% 的圆圈。圆圈出现在整个视口的随机位置。动画在移动设备上看起来不错,但在更大的视口上像素化。

这是动画:https://rimildeyjsr.github.io/spotify-circle-animation/

任何想法如何在所有视口中保持圆圈一致?

jQuery

 var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        function makeDiv(colorChoice){
            var divsize = 10;
            var color = colorChoice;
            console.log(color);
            $newdiv = $('<div/>').css({
                'width':divsize+'px',
                'height':divsize+'px',
                'background-color': color
            });

            var posx = (Math.random() * ($(document).width())).toFixed();
            var posy = (Math.random() * ($(document).height())).toFixed();
            $newdiv.css({
                'position':'absolute',
                'left':posx+'px',
                'top':posy+'px',
                'border-radius':'50%',
                'display':'none'
            }).appendTo( 'body' ).addClass('animate').css({'display':'block'}).one(animationEnd,function(){
                $(this).remove();
            });
        };
        var id = setInterval(function(){makeDiv('black')},5000);

CSS

html,body {
    padding : 0;
    margin: 0;
    height: 100%;
    width: 100%;
    overflow-y: hidden;
    overflow-x: hidden;
}

div {
    height: 10px;
    width:10px;
    background-color: black;
    border-radius: 50%;
    top: 250px;
    right: 10px;
    left: 800px;
}

.animate {
    -webkit-animation: expand 60s;
}

@-webkit-keyframes expand {
    0%{
        -webkit-transform: scale(0,0);
    }

    100%{
        -webkit-transform: scale(100.0,100.0);
        display: none;
    }
}

【问题讨论】:

标签: jquery css


【解决方案1】:

像素化边缘是由transform: scale 引起的。 它将默认情况下为 10 x 10 像素的圆圈拉伸到其大小的 100 倍。

您需要考虑使默认尺寸尽可能大,然后在开始时将其缩小。

链接到更新的小提琴:

https://jsfiddle.net/Lreux3rx/2

【讨论】:

  • 圆圈没有像素化,但它们不再出现在随机位置
  • 由于圆的初始大小,它的中心距离顶部和左侧 500px,因为 xpos 和 ypos 变量将设置它。 500px 是我设置为 1000px 的 divsize 变量的一半。我更新了小提琴来解决这个问题。 jsfiddle.net/Lreux3rx/2
猜你喜欢
  • 2012-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-24
  • 2021-07-30
相关资源
最近更新 更多