2014-01-05 62 views
0

我想使我的「卡」img(s)從屏幕的左側滑到屏幕的中心,就像他們現在一樣。我試着使用:幻燈片在圖像 - jQuery

function FetchCards() { 
    $("#pack").css('margin-left', 0); 
    $("#pack").css('margin-right', 0); 
    $("#pack").animate({ 
     left: '-1000px' 
    }, 'slow'); 
}; 
setTimeout(FetchCards, 7000); 

但它不工作,不知道在哪裏,我應該聲明函數「FetchCards」等,請幫助。這裏是我當前的代碼:

http://plnkr.co/edit/L4wgzTDcV86tZK1eE23D?p=info

什麼我問的是我在哪裏聲明函數「FetchCards」和使圖像無形的,直到他們在滑動將我的代碼工作的?

+0

@AlienArrays不,我把它放在我的PHP下面。 – Journey

+0

在你的示例代碼裏面的plnkr有很多錯誤,我不確定你可以把PHP放在裏面。 - 我認爲PHP回聲很多具有相同ID的圖像... ID必須在html內部是唯一的。您「#pack」的id不在HTML內 – Frogmouth

+0

@Frogmouth哪裏有錯誤,我可以在哪裏上傳我的代碼以正確顯示它? – Journey

回答

1

試試這個:

function FetchCards() { 
    $("#pack").css('margin-left', 0); 
    $("#pack").css('margin-right', 0); 
    $("#pack").animate({ 
    'margin-left': '-1000px' 
    }, 'slow'); 
} 
setTimeout(function(){FetchCards();}, 7000); 
+0

謝謝@AlexShilman你知道我要在代碼中聲明「FetchCards」函數嗎? – Journey

+0

它沒關係。無論如何,所有函數聲明都會被提升到頂部。 –

+0

好吧,那麼如何將該功能添加到我的img標籤?當我嘗試它不顯示任何東西,並表示它期待一個;要麼 , – Journey

0

看我的例子,並告訴我,如果它看起來像你需要什麼... 這裏的例子:http://jsfiddle.net/CAqE4/

JS:

function FetchCards() { 
    $("#pack").css({ 
     'margin-left': 0, 
     'margin-right': 0 
    }).animate({ 
     left: '-=1000px' // -= subtracts the number of pixel 
    },function(){ 
     //this function will be called after #pack animate 
     $(/*IMAGE SELECTOR*/).fadeIn(); //insert the image selector 
    }); 
}; 
setTimeout(FetchCards, 7000); 

CSS: 您的圖片在css中必須有display:none