2013-04-28 57 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