JQuery fading special effect

I want to make the black text of the error message “glow” with a red outline, which disappears after a second, but if updated, returns to “full glow” and starts to disappear again, even if it was not in the first place, completely disappeared. Is there a pretty simple jQuery / CSS way to do this? I think that the two methods of simultaneous attenuation will compete with each other, be asynchronous and all, and I don’t quite know how to generate a luminous effect, or even if it is possible using the standard style.

+1
source share
6 answers

You do not need to use any external plugins, you can only do this with jQuery 1.8 and css3 , but it is not easy. You need to combine the css3 property text-shadowwithanimate()

UPDATE: Bugs fixed.

The blue effect of jsFiddle works here.

JQuery

var red = $(".red");
red.click(function() {
   if ( !$(this).is(':animated') )

    //you just adjust here
    red.glowEffect(0,40,500);
    //which is:
    //red.glowEffect( start value , destination value , duration );
});

$.fn.glowEffect = function(start, end, duration) {
    var $this = this;
    return this.css("a", start).animate({
        a: end
    }, {
        duration: duration,
        step: function(now) {
            $this.css("text-shadow","0px 0px "+now+"px #c61a1a");
        }
    });
};​

CSS

.red { text-shadow: 0px 0px 0px #c61a1a; }

Note. No need to define provider prefixes such as -webkit- -ms- -moz- -o-jQuery 1.8 fixes this automatically.

Source: I asked a question last week, and it came up with great answers:

How to combine jQuery animation with css3 properties without using css transitions?

+5
source

A pure CSS3 solution stolen shamelessly from here :

a.glow, a.glow:hover, a.glow:focus {  
    text-decoration: none;  
    color: #aaf;  
    text-shadow: none;  
    -webkit-transition: 500ms linear 0s;  
    -moz-transition: 500ms linear 0s;  
    -o-transition: 500ms linear 0s;  
    transition: 500ms linear 0s;  
    outline: 0 none;  
} 
a.glow:hover, a.glow:focus  {  
    color: #fff;  
    text-shadow: -1px 1px 8px #ffc, 1px -1px 8px #fff;  
}  
+2
source

barlasapaydin, :

$.fn.glowEffect = function(start, end, duration, callback) {
    // Fetch last animation position
    if (this.data("last-glow")) 
        start = this.data("last-glow");

    return this.animate({
        'placeholder': end // This can be anything, it just a placeholder to allow the animation to run
    }, {
        duration:duration,
        step: function(now, fx) {
            // Calculate current position
            now = parseInt(start + (end - start)*(fx.pos));
            // Set current animation position
            $(fx.elem).css("text-shadow","0px 0px "+now+"px #c61a1a")
                // Save position (if animation is interrupted)
                .data("last-glow", now);
        },
        complete:callback
    });
};

$(".red").click(function() {
    $(this)
        .stop()
        .glowEffect(0,50,1000, // Fade in
                    function() 
                    { 
                        $(this).glowEffect(50,0,1000);  // Fade out
                    });
});

, .

http://jsfiddle.net/Jf4vB/38/

"step":

http://cdmckay.org/blog/2010/03/01/the-jquery-animate-step-callback-function/

+2

jQuery UI , ( CSS3), , ..

0

text-shadow CSS3 $( ". textid" ). stop(). addClass ( "glow", 1000); .

EDIT: , : http://jsfiddle.net/2pBxP/:)

0

JQuery, - :

JQuery fades with loop and delay

You can then use CSS3 to add a glow to the text (or shadow), but note that this is not supported in some browsers.

0
source

All Articles