简体   繁体   English

可以根据背景颜色更改加载指示器颜色吗?

[英]Possible to change loading indicator color based on bg color?

Let's say I have a loading indicator image, I want it to display nicely on any kind of background color.假设我有一个加载指示器图像,我希望它在任何类型的背景颜色上都能很好地显示。

is this possible through some sort of combination of jquery and css?这是否可以通过 jquery 和 css 的某种组合来实现?

jquery to decide if the background is light or dark, and css to apply some sort of mask to the loading indicator to change it's color to the calculated value? jquery 决定背景是亮还是暗,css 对加载指示器应用某种掩码以将其颜色更改为计算值?

Is anything like this out there?外面有这样的吗?

Thanks, Wesley谢谢,韦斯利

Just on the CSS side, you could stack a div on top of your loading image, give it a background-color, and make it see-through.就在 CSS 一侧,您可以在加载图像的顶部堆叠一个 div,给它一个背景颜色,并使其透明。

HTML: HTML:

<div id="loading">
    <img src="loading.gif" alt="Loading..." width="X" height="Y" />
    <div id="loadingColor"></div>
</div>

CSS: CSS:

#loading { position:relative; width:Xpx; height:Ypx }
#loadingColor {
    position:absolute; top:0; left:0;
    width:100%; height:100%;
    opacity:.25; filter:alpha(opacity=25)
}

Then you could just use jQuery to set the actual background-color on #loadingColor :然后你可以使用 jQuery 在#loadingColor上设置实际的background-color

// This would be in your event listener,
// the "before-AJAX-is-sent" function, etc.
$('#loadingColor').css('background-color', '#whatev');

Best of all, it works in IE6+!最重要的是,它适用于 IE6+!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM