How to make a text flash in html/javascript?

后端 未结 9 1737
后悔当初
后悔当初 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条回答
  • 2020-12-18 03:05

    CSS:

    .hidden { visibility: hidden; }
    

    JS:

    setInterval(blinkFunc, 200)
    
    blinkFunc = function () {
      var selector = '#some-selector';
    
      jQuery(selector + ':visible').addClass('hidden');
      jQuery(selector + ':not(:visible)').removeClass('hidden');
    }
    

    That's probably the most cross-browser. Note that Webkit does some crazy stuff with visibility so it might be easier to just change the color.

    0 讨论(0)
  • 2020-12-18 03:06

    You can use something like this

    <html>
    <head>
        <style>
            #blink{
                color:black;opacity:1;font-size:3EM;
            }
        </style>
    </head>
    <body>
        <div id="blink">
            Poop
        </div>
        <script>
            var ops,blink=document.getElementById('blink');
            ops=1
            setInterval(function (){
                ops = (ops < 1) ? 1:0;
                blink.style.opacity=ops;
            },500);
        </script>
    </body>
    

    0 讨论(0)
  • 2020-12-18 03:07

    if you use jQuery you can do something like

    <div id="msg"> <strong>This will blink</strong> </div>
    
    <script type="text/javascript" />
        function blink(selector){
            $(selector).fadeOut('slow', function(){
                $(this).fadeIn('slow', function(){
                    blink(this);
                });
            });
        }
        $(function() {
            blink('#msg');
        });
    </script>
    
    0 讨论(0)
提交回复
热议问题