Bergi(堆栈溢出用户)非常慷慨地帮助我想出了一个使用 jQuery 进行图像交换的解决方案。它现在在悬停时交换,但我想让它在您当前的子站点上保持突出显示(例如,我点击“漫画”页面,“漫画”保持突出显示)。那可能吗?谢谢!
<script type="text/javascript">
var images = {
"comicssubsite": [
"./images/SiteDesign/Comics_subsites_hover.png",
"./images/SiteDesign/Comics_subsites.png"
],
"artworksubsite": [
"./images/SiteDesign/Artwork_subsites_hover.png",
"./images/SiteDesign/Artwork_subsites.png"
],
"aboutsubsite": [
"./images/SiteDesign/About_subsites_hover.png",
"./images/SiteDesign/About_subsites.png"
],
"blog": [
"./images/SiteDesign/Blog_othersites_hover.png",
"./images/SiteDesign/Blog_othersites.png"
],
"facebook": [
"./images/SiteDesign/Facebook_othersites_hover.png",
"./images/SiteDesign/Facebook_othersites.png"
]
};
jQuery(document).ready(function($) {
$("#comicssubsite, #artworksubsite, #aboutsubsite, #blog, #facebook").hover(function(e) {
// mouseover handler
if (this.id in images) // check for key in map
this.src = images[this.id][0];
}, function(e) {
// mouseout handler
if (this.id in images)
this.src = images[this.id][1];
});
});