我有一个类似于Windows的界面,当你点击一个桌面图标时,一个窗口(设置为显示:隐藏;)得到类“可见”。检查数组中的ID是否具有类
.visible {
display: initial !important;
}
我有多个桌面图标和多个窗口。 还有一个任务栏,具有相同的图标。我希望这些在相应的窗口设置为“可见”时突出显示。
.taskbar_icon.hover {
background: #9a3233;
transition: all 300ms ease-in-out;
}
我想这样做的方式是将窗口的ID放入数组中。 然后检查这些窗口中的任何一个是否具有“可见”类。 ,如果他们这样做,添加一类“悬停”到相应的任务栏图标。
这是我到目前为止。
的Jquery:
window.setInterval(function() {
var windows = ["#explorer", "#chrome", "#txt_editor"];
console.log(windows);
if ($(windows).hasClass('visible')) {
$(this + '_taskbar').addClass('hover');
}
else {
$(this + '_taskbar').removeClass('hover');
};
}, 100);
HTML: 桌面图标
<div id="desktop">
<a href="#_" target="#explorer" class="desktop_icon"><img src="img/icons/folder.png"></a>
<a href="#_" target="#chrome" class="desktop_icon"><img src="img/icons/chrome.png"></a>
<a href="#_" target="#txt_editor" class="desktop_icon"><img src="img/icons/word.png"></a>
</div>
的Windows
<div id="explorer" class="window"></div>
<div id="chrome" class="window"></div>
<div id="txt_editor" class="window"></div>
任务栏
<div id="taksbar">
<ul>
<li><a href="#_" target="#explorer" id="explorer_taskbar" class=" taskbar_icon"><img src="img/icons/folder_taskbar.png"></a></li>
<li><a href="#_" target="#chrome" id="chrome_taskbar" class=" taskbar_icon"><img src="img/icons/chrome.png"></a></li>
<li><a href="#_" target="#txt_editor" id="txt_editor_taskbar" class=" taskbar_icon"><img src="img/icons/word_taskbar.png"></a></li>
</ul>
</div>
@Justastudent只是检查现在 –
@Justastudent感谢名单好友 –
就不得不改变 “如果($(值).hasClass(” 可见 “))){” 到 “如果($(值).hasClass(”可见“)){” 但这似乎很好。 谢谢! –