我想要暂时更改我的图像然后当我点击悬停的图像时,我会将其更改为另一个图像.. 但问题是,当我点击onhover图像时,它将保留在onhover图像上,而不是将其更改为点击图像..
我的项目中有2个文件,这里有comp-profile.html和about.html,下面是源代码:
COMP-profile.html:
$("#Content-header-wrapper #link1").unbind("hover").hover(function(){
alert("asd");
$("#Content-header-wrapper #link1").attr("src","Images/Content/link-about-hover.png");
},function(){
$("#Content-header-wrapper #link1").attr("src","Images/Content/link-about.png");
});
$("#Content-header-wrapper #link1").unbind("click").click(function(){
$("#Content-header-wrapper #link1").attr("src","Images/Content/link-comp-profile.png");
$("#Content-header-wrapper #link2").attr("src","Images/Content/link-contact.png");
$("#Content-header-wrapper #link1").attr("alt","link-comp-profile");
$("#Content-header-wrapper #link2").attr("alt","link-contact");
$("#Content-header").html("<img src='Images/Content/header-about.png' alt='header-about' width='273px' height='41'/>");
$("#Content-fill").empty();
$("#Content-fill").load("about-content.html");
$("#Content").fadeOut(0);
$("#Content").animate({opacity: 'toggle', height: 'toggle'},"slow");
});
about.html:
$("#Content-header-wrapper #link1").unbind("hover").hover(function(){
$("#Content-header-wrapper #link1").attr("src","Images/Content/link-comp-profile-hover.png");
},function(){
$("#Content-header-wrapper #link1").attr("src","Images/Content/link-comp-profile.png");
});
另一个奇怪的想法是,每当我将图像悬停在about.html中时,它仍会警告“asd”......
请帮帮我.. ^^
答案 0 :(得分:0)
hover
不是一个事件,因此您无法取消绑定,您需要删除mouseenter
和mouseleave
个事件。
$("#Content-header-wrapper #link1").off("mouseenter mouseleave").hover(function () {
$("#Content-header-wrapper #link1").attr("src", "Images/Content/link-comp-profile-hover.png");
}, function () {
$("#Content-header-wrapper #link1").attr("src", "Images/Content/link-comp-profile.png");
});