所以我有一個段最初有一個ID: #main我如何使這種懸停效果(懸停1按鈕來更改元素的ID,然後當它展開它變回它的原始ID?)[jquery,css3]
和我有一個按鈕:#Button1的
所以,我希望發生的是,當我在周圍徘徊按鈕,我想更改段落的ID爲:#intro
(其中有CSS3風格)
當我將鼠標懸停在按鈕上它應該改變p aragraph的ID爲:#outro
(這也CSS3風格)
,我不喜歡這樣的:
JS
$(document).ready(function(){
$("#button1").hover(function(){
$("#main").attr("id","intro");
},function(){
$("#intro").attr("id","outro");
});
});
CSS
#main{
color:red;
}
#intro{
-webkit-animation: recolor .5s;
color:blue;
}
@-webkit-keyframes recolor {
from{
color:red;
}
to{
color:blue;
}
}
#outro{
-webkit-animation: recolorout .5s;
color:red;
}
@-webkit-keyframes recolorout {
from{
color:blue;
}
to{
color:red;
}
}
這是工作,問題是我只能做一次。我知道,因爲我沒有改回#main
,但在哪裏它把這個一個:
$("#outro").attr("id","main");
,這樣它會懸停處理後更改段回其初始狀態?
還是有其他解決方案嗎?在此先感謝
不改變ID。改用類。 – CodeToad
我已經嘗試過,我有與addClass()和removeClass()相同的問題,我該怎麼做? – Twish
jQuery的[toggleClass()](http://api.jquery.com/toggleclass/)? *諷刺模式關閉* – angabriel