是否可以更改jQuery 高亮效果淡入淡出的颜色?
现在它从黄色开始高光,然后淡入白色,然后淡出。
我最终用黄色突出背景颜色,然后淡化为透明。
我刚刚在 jQuery UI 1.8.9 中也遇到过这种行为,这似乎是一个错误。
对我来说,解决方法是定义我在 CSS 中突出显示的元素的背景颜色,而不是让它默认为透明。
如果未设置背景颜色(即透明),假设您没有更改高亮颜色,则它将元素淡化为黄色,然后变为白色,然后淡出。
但是,如果您设置要突出显示的元素的背景颜色,则当您突出显示它时,它将淡化为黄色,然后变为元素的原始颜色。
$("#id").effect( "highlight",{color:'#FFFF00',easing:'easeInElastic'},4000 );
在效果的选项对象中,您可以将颜色的默认属性更改为您想要的任何内容。我的元素未设置为颜色,它突出显示亮黄色,然后消失。我正在使用 jQuery 1.8.1 和 jQuery-UI。
下面是jQuery UI 1.8.9中的高亮效果源码。看起来它不应该褪色为白色......它应该从黄色(#ffff99 或您传入的颜色选项)褪色为原始背景颜色,该背景颜色缓存在变量animation
. 您使用的是 1.8.9 吗?
/*
* jQuery UI Effects Highlight 1.8.9
*
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* http://docs.jquery.com/UI/Effects/Highlight
*
* Depends:
* jquery.effects.core.js
*/
(function( $, undefined ) {
$.effects.highlight = function(o) {
return this.queue(function() {
var elem = $(this),
props = ['backgroundImage', 'backgroundColor', 'opacity'],
mode = $.effects.setMode(elem, o.options.mode || 'show'),
animation = {
backgroundColor: elem.css('backgroundColor')
};
if (mode == 'hide') {
animation.opacity = 0;
}
$.effects.save(elem, props);
elem
.show()
.css({
backgroundImage: 'none',
backgroundColor: o.options.color || '#ffff99'
})
.animate(animation, {
queue: false,
duration: o.duration,
easing: o.options.easing,
complete: function() {
(mode == 'hide' && elem.hide());
$.effects.restore(elem, props);
(mode == 'show' && !$.support.opacity && this.style.removeAttribute('filter'));
(o.callback && o.callback.apply(this, arguments));
elem.dequeue();
}
});
});
};
使用 jQuery Color 插件:https ://github.com/jquery/jquery-color
有了它,您可以突出显示元素并正确淡入透明。