css - 更改动画中的占位符颜色

标签 css

我不知道如何在文本输入中制作动画颜色变化。

这是CSS:

@keyframes anim {
    0% {
        opacity: 0.2;
        color:blue;
    }

    70% {
        opacity: 1;
        color: red;
    }

    100% {
        opacity: 0.1;
        color: blue;
    }
}

input,
input::-webkit-input-placeholder {
    animation: anim 4s;

}

HTML:

<input type="text" placeholder="Hello" />

JsBin: https://jsbin.com/yejiwipego/1/edit?html,css,output

不透明度变化很好。 我一定是遗漏了什么?

最佳答案

我有点让它工作了,但占位符文本的不透明度似乎有点困惑。我希望这是(某种程度上)您的意思:

编辑;我让它工作得更好。检查新的 JSFiddle

更新版本:https://jsfiddle.net/oycnfxw4/

element {
  --main-text-color: rgba(0,0,255,0.8);
}

input, input::-webkit-input-placeholder {
    color: var(--main-text-color);
    -webkit-animation: anim 4s linear 1 forwards;
    animation: anim 4s linear 1 forwards;
}

@keyframes anim {
    0% {
        opacity: 0.2;
        --main-text-color: rgba(0,0,255,0.2);
    }

    70% {
        opacity: 1;
        --main-text-color: rgba(255,0,0,1);
    }

    100% {
        opacity: 0.1;
        --main-text-color: rgba(0,0,255,0.5);
    }
}

关于css - 更改动画中的占位符颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43299503/

相关文章:

html - 如何在 CSS/HTML 中引用计算机目录中的图像作为背景图像

html - 喜欢点击时的图标颜色

javascript - 是否可以在CSS3或Javascript中将字母映射到圆柱体或球体?

javascript - 如何使用 CKEditor 为 <table> 添加悬停效果?

html - -webkit-转换 : scale() not displaying properly in OSX Safari

ruby-on-rails - 为不同的布局使用不同的 CSS

html - div布局定位有问题

html - 具有固定位置的导航栏和具有相对位置的内容

javascript - 如何让 Bootstrap 3 在下拉单击时下推页面内容

javascript - 学校元素 - 带有图钉和 onclick 事件的 IMG