【问题标题】:CSS/HTML/JQuery - How do i make a textbox blink with a glow effect?CSS/HTML/JQuery - 如何让文本框闪烁发光效果?
【发布时间】:2013-10-29 11:08:18
【问题描述】:

所以,我一直在尝试让文本框闪烁 3 次,并带有发光效果。 但我只能让它闪烁一次。

有人可以看看这个,也许可以在这里帮助我吗?

HTML

<input id="asktextsearch" name="search" type="text" placeholder="bla bla" />

CSS

#asktextsearch{
    height: 20px;
    width: 440px;
    font-size: 12px;
    color: Grey;
    border: thin solid #CACACA;
    //margin-top: 60px;
    /* [disabled]border-radius: 10px 10px 10px 10px; */

    outline:none;
    transition: all 0.25s ease-in-out;
    -webkit-transition: all 0.25s ease-in-out;
    -moz-transition: all 0.25s ease-in-out;
}

#asktextsearch:focus {
    box-shadow: 0 0 5px rgba(209, 27, 28, 1);
    -webkit-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
    -moz-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
}

JQuery

    for(i=0;i<3;i++){
        alert(i);
        $('#asktextsearch').focus();
        //$('#asktextsearch').addClass(':focus');
    };

【问题讨论】:

    标签: jquery html css textbox focus


    【解决方案1】:

    LIVE DEMO

    JS:

    $(function(){
    
        var count    = 0, 
            $input   = $('#asktextsearch'), 
            interval = setInterval(function() {
    
        if ($input.hasClass('blur')) {
    
              $input.removeClass('blur').addClass('focus'); 
              ++count;
    
        } else {
    
              $input.removeClass('focus').addClass('blur');
        }
    
           if (count === 3) { 
    
               clearInterval(interval); 
           }
    
        }, 300);
    });
    

    【讨论】:

      【解决方案2】:

      也许是这样的 CSS

      #asktextsearch{
      height: 20px;
      width: 440px;
      font-size: 12px;
      color: Grey;
      border: thin solid #CACACA;
      //margin-top: 60px;
      /* [disabled]border-radius: 10px 10px 10px 10px; */
      
      outline:none;
      transition: all 0.25s ease-in-out;
      -webkit-transition: all 0.25s ease-in-out;
      -moz-transition: all 0.25s ease-in-out; }
      
      #asktextsearch.focus {
      box-shadow: 0 0 5px rgba(209, 27, 28, 1);
      -webkit-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
      -moz-box-shadow: 0 0 5px rgba(209, 27, 28, 1);  }
      

      JS

      var count = 0;
      var p = setInterval(function(){
      if(count==6) 
          window.clearInterval(p);
      $('#asktextsearch').toggleClass("focus");
      count++;    
      },500);
      

      【讨论】:

        【解决方案3】:
        #asktextsearch{
        height: 20px;
        width: 440px;
        font-size: 12px;
        color: Grey;
        border: thin solid #CACACA;
        //margin-top: 60px;
        /* [disabled]border-radius: 10px 10px 10px 10px; */
        
        outline:none;
        transition: all 0.25s ease-in-out;
        -webkit-transition: all 0.25s ease-in-out;
        -moz-transition: all 0.25s ease-in-out;
        }
        
        .blink {
        box-shadow: 0 0 5px rgba(209, 27, 28, 1);
        -webkit-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
        -moz-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
        }
        

        在 javascript 中:

        for(i=1; i <= 5; i++){           
            $('#asktextsearch').focus();
            setTimeout(function(){
               $('#asktextsearch').toggleClass('blink');
            }, (300 * i));
         }
        

        【讨论】:

          【解决方案4】:

          希望对你有帮助!!!代码我草稿理解有限,大家可以根据需要自定义代码。

             var counter = 0;
             var ID;
                $(document).ready(function() {
                     $("#asktextsearch").focus(function(){
                        counter = 0;
                            $(this).addClass('focusing');
                              setTimer();
                           });       
                });
          
            function setTimer(){          
                  ID = setInterval(function () {
                          startSlider(counter);
                         counter++;
                         console.log(counter);
                      }, 4000);  // adjust delay here     
          
               }
          
          function startSlider(){
              if(counter>3){
                  stopFocus();
                  clearInterval(ID);          
              }else{
               $('#asktextsearch').toggleClass('focusing'); 
              }
          }
          
          function stopFocus() {
              $("#asktextsearch").removeClass('focusing');
          }
          

          css:

            #asktextsearch{
                height: 20px;
                width: 440px;
                font-size: 12px;
                color: Grey;
                border: thin solid #CACACA;
                outline:none;
                transition: all 0.25s ease-in-out;
                -webkit-transition: all 0.25s ease-in-out;
                -moz-transition: all 0.25s ease-in-out;
            }
          
            .focusing {
                box-shadow: 0 0 5px rgba(209, 27, 28, 1);
                -webkit-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
                -moz-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
            }
          

          演示链接:http://jsfiddle.net/7ABNY/

          【讨论】:

            【解决方案5】:

            css:

            #asktextsearch{
                height: 20px;
                width: 440px;
                font-size: 12px;
                color: Grey;
                border: thin solid #CACACA;
                //margin-top: 60px;
                /* [disabled]border-radius: 10px 10px 10px 10px; */
                outline:none;
                transition: all 0.25s ease-in-out;
                -webkit-transition: all 0.25s ease-in-out;
                -moz-transition: all 0.25s ease-in-out;
            }
            
            #asktextsearch:focus {
                box-shadow: 0 0 5px rgba(209, 27, 28, 1);
                -webkit-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
                -moz-box-shadow: 0 0 5px rgba(209, 27, 28, 1); 
            }
                    .blink {
                        animation: blink 1.5s steps(3, start) 3;
                        }
            
                    @keyframes blink {
                         to {
                         visibility: hidden;
                            }
                        }
            

            html:

            <div class="blink">
                        <input id="asktextsearch"  name="search" type="text" placeholder="bla bla" />
                </div>
            

            演示:http://jsfiddle.net/rakeshgajjar/TNDyL/

            【讨论】:

              猜你喜欢
              • 2018-05-10
              • 2011-12-22
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2010-10-10
              • 2021-11-03
              • 1970-01-01
              相关资源
              最近更新 更多