我需要在我的应用程序中有一个闪烁功能。基本上,我正在创建一个计算器,在用户通过按钮输入每个数字后,我需要像"|“这样的东西来闪烁。对于firefox和opera,类似于:
var str = "Hello world!";
document.write(str.blink());这正是我想要的。我的问题是,它们不能在Chrome、IE或safari中运行。有没有什么简单的替代方法,或者如果我想让我的应用程序在跨浏览器上运行,我必须自己创建闪烁功能?
发布于 2013-07-16 22:48:54
试试这个-:解决方案1号
您可以创建自己的自定义闪烁function.This,也可以通过创建css类并将其添加到我们的元素中来完成。
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
function blink()
{
document.getElementById('blink').className = "animated blink_css";
}css中的
.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!
发布于 2013-07-16 22:47:07
你可以只使用css3:
@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); }
}发布于 2013-07-16 22:47:55
如果你真的想要跨浏览器的兼容性,你应该使用库,例如jQuery。
下面是一个很好的小脚本,它可以实现您想要的功能-- http://www.silverphp.com/simple-jquery-blink-script-alternative-to-html-blink-tag.html
另一方面,如果您更喜欢普通的JS,您可能必须自己实现它。也许可以使用setInterval()的一个函数来使元素消失?
https://stackoverflow.com/questions/17679660
复制相似问题