简体   繁体   English

在Wordpress中的x秒后隐藏div

[英]Hiding a div after x seconds in wordpress

I would like to hide a picture in a div after 10 seconds using Javascript. 我想在10秒钟后使用Javascript将图片隐藏在div中。 The div i have is in the footer.php along with the script I researched to hide but it is not working. 我拥有的div以及我研究隐藏的脚本都在footer.php中,但它无法正常工作。 Any ideas?? 有任何想法吗?? Below is a snippet of my code. 以下是我的代码片段。

<--footer.php--> <-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--> <-footer.php->

Do i need to have something in my stylesheet.css to reference the #hide??? 我是否需要在stylesheet.css中添加一些内容以引用#hide ???

Thanks in advance. 提前致谢。 Paul 保罗

You code is correct and should work if you have also included a jQuery library. 您的代码是正确的,并且如果还包含jQuery库,则应该可以正常工作。

For example: 例如:

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

Be sure that you include jquery properly: 确保正确包含jquery:

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

How do I add a simple jQuery script to WordPress? 如何在WordPress中添加简单的jQuery脚本?

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

use jQuery() instead of $() in wordpress environment. 在WordPress环境中使用jQuery()代替$() or you can: 或者您可以:

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

and No, you dont need to have something in stylesheet that refer to the div 不,您不需要在样式表中引用div

good luck ! 祝好运 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM