How to make a text flash in html/javascript?

后端 未结 9 1816
后悔当初
后悔当初 2020-12-18 02:13

I know flashing text is banned at many places but still as my client requires it, I need to flash one line of text using HTML, JavaScript which ever is feasible. I would lik

9条回答
  •  猫巷女王i
    2020-12-18 03:00

    You can do something like this:

    Blink

    With the script:

    $(document).ready(function() {
        var f = document.getElementById('Foo');
        setInterval(function() {
            f.style.display = (f.style.display == 'none' ? '' : 'none');
        }, 1000);
    
    });
    

    Sample: http://jsfiddle.net/7XRcJ/

    If you're not using jQuery, you can try something like this:

    window.addEventListener("load", function() {
        var f = document.getElementById('Foo');
        setInterval(function() {
            f.style.display = (f.style.display == 'none' ? '' : 'none');
        }, 1000);
    
    }, false);
    

    Various browsers have different ways of binding event handlers, so I would strongly suggest using some sort of cross-browser library for this sort of thing if possible.

    You can also try using the onload event in the body tag. Here's a full example that I've tested in FF and IE7:

    function blink() {
       var f = document.getElementById('Foo');
       setInterval(function() {
          f.style.display = (f.style.display == 'none' ? '' : 'none');
       }, 1000);
    }
    
    
    
    
    Blink

提交回复
热议问题