得到“原始"的悬停在对象上时(非悬停)对象的背景色 [英] Get "original" (non-hover) background color of object when hovering over it
本文介绍了得到“原始"的悬停在对象上时(非悬停)对象的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下功能获取任何元素的背景色:
I can get the background color of any element with the following functions:
$('.example').css('background')
但是,在我的情况下,鼠标移动到该元素上,并且由于CSS :hover
伪类,我收到了经过修改的颜色.
However, in my case, the mouse is moving over this element and I receive a modified color because of a CSS :hover
pseudo-class.
有什么办法可以接收原始颜色?
Is there any way to receive original color? Something like
$('.example').cssWithoutHover('background')
您可以在此处进行测试.在最后一个单元格中放入5.动画后,此单元格的颜色将更改.
You can test it here. Just put 5 in the last cell. The color of this cell will change after animation.
推荐答案
您可以对DOM ready上的起始BG颜色进行扫描,并将它们存储为数据属性.
You could do a sweep of the starting BG colours on DOM ready and store these as data attributes.
var board = $('#board-numbers');
board.children('div').each(function() {
$(this).data('start-bg', $(this).css('background'));
});
board.on('hover', 'div', function() {
var curr_bg = $(this).css('background');
var start_bg = $(this).data('start-bg');
});
这篇关于得到“原始"的悬停在对象上时(非悬停)对象的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文