jQuery 闪烁/Flash 动画

发布于 2024-08-18 11:34:33 字数 82 浏览 3 评论 0原文

有谁知道一个简洁的 jQuery 效果可以使图像随机闪烁或闪烁?这里的大多数帖子都是“如何停止闪烁”等,因此很难找到有关实际故意使图像闪烁的任何内容。

Does anyone know of a neat jQuery effect that will make an image randomly flicker or flash? Most of the posts on here are "how to stop flickering" etc, so it's pretty hard to find anything about actually making the image flicker ON PURPOSE.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏有森光若流苏 2024-08-25 11:34:33

将此作为您的 HTML:

<img id="test" src="http://sstatic.net/so/img/logo.png">

将此用作您的 javascript:

$(document).ready(
function(){
    var t;
    const fparam = 100;
    const uparam = 100;
    window.flickr = function(){
        if(Math.round(Math.random())){
            $("#test").css("visibility","hidden");
            t = setTimeout('window.unflickr()',uparam);
        }
        else
            t = setTimeout('window.flickr()',fparam);
    }
    window.unflickr = function(){
        if(Math.round(Math.random())){
            $("#test").css("visibility","visible");
            t = setTimeout('window.flickr()',fparam);
        }
        else
            t = setTimeout('window.unflickr()',uparam);
    }

    t = setTimeout('window.flickr()',fparam);
});

如果有人对此有反馈,请告诉我。我不确定这是否是最安全的做事方法。我倾向于避免使用 setTimeout,但我不知道还有其他方法可以做到这一点。这是随机闪烁,因此当 img 可见时,它将每 100 秒以 0.5 的概率设置为隐藏,而当它隐藏时,每 100 秒将以 0.5 的概率将其设置为可见。可以针对不同类型的闪烁调整超时参数。

让我知道你的想法。

With this as your HTML:

<img id="test" src="http://sstatic.net/so/img/logo.png">

Use this as your javascript:

$(document).ready(
function(){
    var t;
    const fparam = 100;
    const uparam = 100;
    window.flickr = function(){
        if(Math.round(Math.random())){
            $("#test").css("visibility","hidden");
            t = setTimeout('window.unflickr()',uparam);
        }
        else
            t = setTimeout('window.flickr()',fparam);
    }
    window.unflickr = function(){
        if(Math.round(Math.random())){
            $("#test").css("visibility","visible");
            t = setTimeout('window.flickr()',fparam);
        }
        else
            t = setTimeout('window.unflickr()',uparam);
    }

    t = setTimeout('window.flickr()',fparam);
});

If anyone has feedback on this, lemme know. I'm not sure if this is the safest method of doing things. I tend to avoid using setTimeout, but I don't know of any other way to do this. This is a random flicker so when the img is visible, it will be set to hidden with 0.5 probability every 100 seconds and when it is hidden, it will be set to visible with 0.5 probability every 100 seconds. The timeout parameters can be tuned for different kinds of flickers.

Let me know what you think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文