Animating elements of text-shadow with jQuery

后端 未结 5 414
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 20:40

I was wondering if there was any way to, using jQuery, animate properties of text-shadow like size or colour.

It\'s annoying that there aren\'t individual properties

相关标签:
5条回答
  • 2020-12-17 20:58

    Why not using addClass('shadow'), and adding a transition on the element?

    Of course this doesn't work in old IE...

    0 讨论(0)
  • 2020-12-17 21:00

    As an alternative to using jQuery, you can use the powerful animation capabilities of the UIZE JavaScript Framework. See different elements of multiple text shadows being animated at the same time in the following example...

    http://www.uize.com/examples/hover-fader-text-shadow-animation.html

    0 讨论(0)
  • 2020-12-17 21:09

    Might be a little late for this answer, but here it is anyway...

    I solved it by implementing a "virtual" css-property to be animated like this

    $.fx.step.textShadowBlur = function(fx) {
      $(fx.elem).css({textShadow: '0 0 ' + Math.floor(fx.now) + 'px black'});
    };
    
    $(el).css({textShadowBlur:20})
        .animate({textShadowBlur:1}, {duration: 1000});
    

    This is described in more detail here: http://usefulthink.com/2010-12/animating-text-shadow-using-jquery

    Some other approaches can be found here: http://forum.jquery.com/topic/let-s-animate-text-shadow

    0 讨论(0)
  • 2020-12-17 21:17

    The only way I found that truly worked was creating a <span> with the same text as the <a> and overlaying it using absolute positioning, negative margins, and .fadeIn()/.fadeOut() or opacity animations. But even that was glitchy at best because of all the on the fly expanding of elements and the overlay was kind of 'off' looking at best.

    0 讨论(0)
  • 2020-12-17 21:18

    Use javascript to parse the CSS property and create a new one

    var myelement_shadow = $('myelement').css('text-shadow');
    

    will give you the property

    Use javascript's String functions to work with it: http://www.w3schools.com/jsref/jsref_obj_string.asp and parsefloat('2px') will give you just the 2

    0 讨论(0)
提交回复
热议问题