2014-01-05 57 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