[英]jquery-ui switchClass() not working as expected
我無法像在jquery站點上的示例中那樣使switchClass函數很好地淡出。 基本上,時間安排似乎沒有任何影響,我嘗試從40000-4開始嘗試,但沒有任何區別。
我在下面貼了一個小提琴(解釋得更好),但這是我正在使用的代碼。 有兩個用於切換類的div,因此背景圖片不同。 我為每個div使用不同的方法,但是即使一個使用switchClass,另一個使用addClass,它們都給出完全相同的結果。
$(document).ready(function() {
$('.iamatrainer').hover(function(){
$(this).switchClass('iamatrainer', 'iamatrainerhover', 400, 'easeInOutQuad');
}, function(){
$(this).switchClass('iamatrainerhover', 'iamatrainer', 400, 'easeInOutQuad');
});
$('.iusetrainer').hover(function(){
$(this).addClass('iusetrainerhover', 400);
}, function(){
$(this).removeClass('iusetrainerhover', 400);
});
});
誰能幫我嗎?
您確定您已加載jQueryUI嗎? switchClass方法不是jQuery的一部分。 您的小提琴正在拋出JS控制台錯誤。
您實際上不需要JS。 只需在.iamatrainer
和.iusetrainer
元素上設置:hover
就可以了。 http://jsfiddle.net/y3ALr/3/
另外,如果您必須使用背景圖片...
您可以使用:hover
偽選擇器和css transitions
.iamatrainer{
background:url(http://renegadeox.com/iamatrainer.png);
height:70px;
width:512px;
transition: background 0.3s linear;
}
.iamatrainer:hover{
background:url(http://renegadeox.com/iamatrainerhover.png);
height:70px;
width:512px;
transition: background 0.3s linear;
}
另外,最好將圖像合並為一個,並將background-position
用於:hover
狀態
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.