添加介绍图像fadeIn wordpress

时间:2014-03-10 21:10:42

标签: php jquery css wordpress

我想添加淡入淡出的图像,然后在一定时间后淡出。我试图将下面的代码添加到index.php中并且它可以工作,但它会抛出一切,如对齐和间距。我会把它放在哪里,以便只在主页首次加载时加载?

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<img style="display: none; z-index: 9999;" id="book" src="images/test.jpg" alt="" width="100%" height="100%">

<script>    
    $( "#book" ).fadeIn ( 2500, function() {});
    $( "#book" ).fadeOut( 1000, function() {});
</script>

2 个答案:

答案 0 :(得分:1)

准备好一切后运行你的功能

$( document ).ready(function() {
 //your code
});

它可能有效。

并看看 http://codex.wordpress.org/Function_Reference/wp_enqueue_script

答案 1 :(得分:1)

在准备就绪时使用文档,它将在加载文档时触发一个函数:

<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<img style="display: none; z-index: 9999;" id="book" src="images/test.jpg" alt="" width="100%" height="100%">

<script>    
   $(document).ready(function(){
    $( "#book" ).fadeIn ( 2500, function() {});
    $( "#book" ).fadeOut( 1000, function() {});
  });
</script>

让我知道它是否有效