How do I animate a background color to transparent in jQuery?

后端 未结 12 1788
慢半拍i
慢半拍i 2020-12-09 14:46

I can animate from transparent to color, but when I tell jquery to animate the backgroundColor: \'transparent\' it just changes to white. Any idea how to fix this?

12条回答
  •  长情又很酷
    2020-12-09 15:07

    I changed Shog9's code a bit to fit my needs. It's sort of like the jQuery UI Highlight, only it does not fade into white. It's not perfect, but it works on most elements

    function highlight(element, color, speed) {
    if (speed == null) speed = "fast";
    var e;
    var position;
    element.each(function() {
        e = $(this);
        position = e.css('position');
        if (position != 'absolute')
            e.css('position', 'relative');
        log(position);
        e.append($("
    ") .css({ backgroundColor: color, position: 'absolute', top: 0, left: 0, zIndex: -1, display: "none", width: e.width(), height: e.height() }).fadeIn(speed).fadeOut(speed, function() { $(this).remove(); e.css('position', position); }) ); }); }

提交回复
热议问题