我們如何基於內聯變量的值更改來分配類?基於變化的內聯變量的值添加類?
這裏是一個更容易理解的演示: http://jsfiddle.net/eYGr5/75/
基本上,另一個腳本(我不想碰)被指定爲內嵌樣式覈實。我想確定何時「IF」這個樣式的值發生了變化,以便將某個類應用於某個元素。
這裏是代碼的縮小的非交互副本:
HTML:
<div class="mm-active">mm-active</div>
<div class="mm-container" style="color:DarkGreen;">mm-container: By hovering here, the jQuery should look up the new inline style (DeepPink) and ONLY because of that inline style, turn mm-active lime green!</div>
CSS:
.activefix {
background:Lime;
}
的jQuery:
// This function gets the value of an inline style property, (Source: bit.ly/1er8vJ2):
(function($) {
$.fn.inlineStyle = function (prop) {
return this.prop("style")[$.camelCase(prop)];
};
}(jQuery));
// Now how do we assign a class based on what this inline variable changes to?
if ($(".mm-container").inlineStyle("color") == 'DeepPink') {
$('.mm-active').addClass('activefix'); // This should apply "Lime" to mm-active
}
其他JS文件是否使用.addClass?如果是這種情況,我們可以覆蓋它來包含事件處理程序。 –
他說另一個JS文件正在修改樣式,而不是類。 – Barmar
@JFit Barmar說了些什麼。更具體地說,我將改變的實際內聯樣式是「顯示」,它具有從「塊」切換到「無」的值。 – WebMW