利用jquery实现图片显隐特效

首先需要在header.php中加载jquery,可以使用外链也可以内链。 外链可以利用google为我们提供的JS库,据说可以提高js加载速度,格式如下:

1
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.2.3.min.js"></script>

内链格式为:

1
<script type="text/javascript" src="<?php bloginfo('stylesheet_directory'); ?>/js/jquery.min.js" ></script>

然后再在header.php中添加:

1
<script type="text/javascript">
1
$(function () {
1
$('img').hover(
1
function() {$(this).fadeTo("fast", 0.5);},
1
function() {$(this).fadeTo("fast", 1);
1
});
1
});
1
</script>