首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >blink()方法的替代方法

blink()方法的替代方法
EN

Stack Overflow用户
提问于 2013-07-16 22:42:39
回答 3查看 1.8K关注 0票数 2

我需要在我的应用程序中有一个闪烁功能。基本上,我正在创建一个计算器,在用户通过按钮输入每个数字后,我需要像"|“这样的东西来闪烁。对于firefox和opera,类似于:

代码语言:javascript
复制
var str = "Hello world!";
document.write(str.blink());

这正是我想要的。我的问题是,它们不能在Chrome、IE或safari中运行。有没有什么简单的替代方法,或者如果我想让我的应用程序在跨浏览器上运行,我必须自己创建闪烁功能?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-07-16 22:48:54

试试这个-:解决方案1号

您可以创建自己的自定义闪烁function.This,也可以通过创建css类并将其添加到我们的元素中来完成。

代码语言:javascript
复制
function blink()
    {
        setInterval(function () {
            document.getElementById("blink").style.webkitTransitionDuration = "0.7s";
            document.getElementById("blink").style.opacity = 0;
            setTimeout(function () {
                document.getElementById("blink").style.webkitTransitionDuration = "0.7s";
                document.getElementById("blink").style.opacity = 1;
            }, 700);
        },1400);

    }

试试这个-->解决方案2号

JAVASCRIPT

代码语言:javascript
复制
function blink()
        {       
document.getElementById('blink').className = "animated blink_css";
        }

css中的

代码语言:javascript
复制
.animated {
    -webkit-animation-fill-mode:both;
    -moz-animation-fill-mode:both;
    -ms-animation-fill-mode:both;
    -o-animation-fill-mode:both;
    animation-fill-mode:both;
    -webkit-animation-duration:1s;
    -moz-animation-duration:1s;
    -ms-animation-duration:1s;
    -o-animation-duration:1s;
    animation-duration:1s;
}

  @keyframes 'blink' {
   0% { background: rgba(255,0,0,0.5); }
   50% { background: rgba(255,0,0,0); }
   100% { background: rgba(255,0,0,0.5); 
}
//try moz for mozilla,o for opera and webkit for safari and chrome 
    .blink_css {
        -webkit-animation-name: blink;
        -moz-animation-name: blink;
        -o-animation-name: blink;
        animation-name: blink;
    }

他们两个都会work.Tested!

票数 1
EN

Stack Overflow用户

发布于 2013-07-16 22:47:07

你可以只使用css3:

代码语言:javascript
复制
@keyframes 'blink' {
   0% { background: rgba(255,0,0,0.5); }
   50% { background: rgba(255,0,0,0); }
   100% { background: rgba(255,0,0,0.5); }
}
票数 4
EN

Stack Overflow用户

发布于 2013-07-16 22:47:55

如果你真的想要跨浏览器的兼容性,你应该使用库,例如jQuery。

下面是一个很好的小脚本,它可以实现您想要的功能-- http://www.silverphp.com/simple-jquery-blink-script-alternative-to-html-blink-tag.html

另一方面,如果您更喜欢普通的JS,您可能必须自己实现它。也许可以使用setInterval()的一个函数来使元素消失?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17679660

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档