2013-04-28 61 views
0

我想用Javascript在10秒後隱藏div中的圖片。我擁有的div與footer.php一起,我研究的腳本隱藏,但它不起作用。有任何想法嗎??以下是我的代碼片段。在wordpress中x秒後隱藏div

< --footer.php - >

<div id="hide"> 
    <img src="http://www.example.com/image.png"> 
</div> 


<script type="text/javascript"> 
    setTimeout(function() { 
    $('#hide').hide(); 
}, 10000); 
</script> 

< --footer.php - >

我是否需要在我的stylesheet.css中一些引用#hide? ??

在此先感謝。 Paul

回答

0

要確保你有適當的jQuery:

http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/

How do I add a simple jQuery script to WordPress?

http://www.ericmmartin.com/5-tips-for-using-jquery-with-wordpress/

使用jQuery()而不是在wordpress環境中的$()。或者您可以:

jQuery(function($){ 
    setTimeout(function() { 
    $('#hide').hide();}, 
    10000); 
}); 

也沒有,你不需要在樣式表,它指的是div

運氣好東西!

+0

Yeaaaaahhhhh ...你做了它的人..非常感謝你,我打破了我的頭,試圖找出它,它的工作。 ... – Paul 2013-04-28 00:51:43

+0

恭喜!高興可以幫助:) – egig 2013-04-28 00:54:25

0

你的代碼是正確的,如果你還包括一個jQuery庫應該工作。

例如:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
+0

我仍然必須做錯事情,因爲它不適合我:( – Paul 2013-04-28 00:38:18