2015-09-11 24 views
0

我有一些價格根據單選按鈕選擇進行調整。我知道如何根據選擇使數字發生變化,但我怎樣才能同時讓他們閃光以吸引用戶的眼球呢?如何在Jquery中根據單選按鈕選擇更改數字?

我嘗試這樣做:https://stackoverflow.com/a/11915453/5067193

而且它適用於第一個單選按鈕的變化,但沒有任何後續變化。每次單選按鈕選擇更改時,我都希望它閃爍。

編輯:

我發現,我工作了答案:

我不得不添加一個setTimeout函數所以現在我的jQuery代碼看起來像(替換爲$ JQ):

jq("input:radio").click(function(){ 
    console.log('radio clicked'); 

    jq("#price").addClass("flash"); 

    setTimeout(function(){ 
     jq("#price").removeClass("flash"); 
    }, 1000); 


}); 

和我現在的閃存css看起來像:

.flash{ 

    -moz-animation: flash 1s ease-out; 
    -moz-animation-iteration-count: 1; 

    -webkit-animation: flash 1s ease-out; 
    -webkit-animation-iteration-count: 1; 

    -ms-animation: flash 1s ease-out; 
    -ms-animation-iteration-count: 1; 

} 

@-webkit-keyframes flash { 
    0% { color:transparent;} 
    50% { color:#FFF;}   
    100% {color:transparent;} 
} 

@-moz-keyframes flash { 
    0% { color:transparent;} 
    50% { color:#FFF;}   
    100% {color:transparent;} 
} 

@-ms-keyframes flash { 
    0% { color:transparent;} 
    50% { color:#FFF;}   
    100% {color:transparent;} 
} 
+1

發佈您的代碼在你的問題吧。 – j08691

+0

查看您提到的Stackoverflow答案中的評論。這有一個解決您的問題。 http://jsfiddle.net/daCrosby/eTcXX/1/ – mechanicals

+0

謝謝@mechanicals,增加超時是答案!我將編輯我的帖子以反映更改 – Will

回答

0

你可以使用,但你需要一個「jQuer Y(選擇器).removeClass( 「閃光」);」第一。因此,每次調用它時,它都會刪除並添加閃光燈。

事情是這樣的:

function $(".flashyRadio").click(function(){ 

$("#price").removeClass("flash").addClass("flash"); 

}) 
+0

如果您在添加該類後才刪除該類,則該動畫將無法使用。要麼你需要排序超時,以便動畫完成。 – mechanicals

+0

沒有。刪除它之前,你添加它。 –

+1

謝謝@davidtallon,不幸的是,雖然我無法讓你的修復程序爲我工作。我不得不添加一個setTimeout函數來讓它在我的編輯中看到工作。 – Will

相關問題