我有以下代碼: -jQuery的 - 圖像替換動畫(切換)
HTML
<div class="mobile-menu"></div>
CSS
.mobile-menu {
background: url(../img/buttons/menu-01.png);
background-repeat: no-repeat;
height: 26px;
width: 26px;
display: inline-block;
margin: 7px 0;
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
}
的jQuery
$('.mobile-menu').click(function(event){
var index = 0;
var imagesArray = ["http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-01.png",
"http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-02.png",
"http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-03.png",
"http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-04.png",
"http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-05.png",
"http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-06.png",
"http://planetbounce.m360.co.uk//wp-content/themes/planetbounce/assets/img/buttons/menu-07.png"];
var background1 = $(".mobile-menu");
var background2 = $(".mobile-menu");
//Set the starting background
background2.css("background","url('"+ imagesArray[index] +"')");
interval = setInterval(changeImage,30);
interval;
function changeImage(){
background2.css("background","url('"+ imagesArray[index] +"')");
//Hide the top element which we will load the "new" background in now
background1.fadeOut(10);
index++;
if(index == 6) {
clearInterval(interval); // stop the interval
}
if(index >= imagesArray.length){
index = 0;
}
//Set the background of the top element to the new background
background1.css("background","url('"+ imagesArray[index] +"')");
//Fade in the top element
background1.fadeIn(10);
}
});
基本上這動畫我想要的7個不同的圖像之間。在下一次單擊時,循環需要反過來,所以它將菜單-07加載到菜單01(因此某種切換來運行此功能的相反)。
我該如何做到這一點?
你確定你的小提琴在工作? –
@Reddy是啊我只是試過嗎? – nsilva
這只是一個灰色的箭頭,從向下指向指向上點擊,需要做相反的第二次點擊,實質上是在每次點擊時在兩者之間切換 – nsilva