jquery渐隐渐显的图片幻灯闪烁切换实现方法
jquery渐隐渐显的图片幻灯闪烁切换实现方法
发布时间:2016-12-30 来源:查字典编辑
摘要:本文实例讲述了jquery渐隐渐显的图片幻灯闪烁切换实现方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:jQuery渐隐渐显...

本文实例讲述了jquery渐隐渐显的图片幻灯闪烁切换实现方法。分享给大家供大家参考。具体实现方法如下:

复制代码 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>jQuery渐隐渐显的图片幻灯闪烁切换效果</title>

<meta http-equiv="content-type" content="text/html;charset=gb2312">

<>

<style type="text/css">

body{font-size:12px;letter-spacing:1px;font-family:"Microsoft YaHei";line-height:1.8em;}

div,ul,li{margin:0;padding:0;}

.slides{position:relative;width:700px;height:300px;overflow:hidden;border:1px solid #ccc;}

.slides img{width:700px; height:300px;}

.slides .ico{position:absolute; right:8px;bottom:6px;}

.slides .ico li{background:#fff;float:left;display:block;width:15px;height:15px;line-height:15px;border:1px solid #cecece;font-family:Arial,Helvetica,sans-serif;text-align:center;margin:2px;padding:1px;cursor:pointer;}

.slides .ico li.high{background:#7f0019;color:#fff;font-weight:bolder;}

</style>

<script language="javascript" src="js/jquery-1.4.2.min.js"></script>

<script language="javascript">

$(function(){

var _img=$('.slides img');

var _len=_img.length;

var _index=0;

var _moving;

//插入图片索引数字

var _ul='<ul>'

for(var i=1; i<=_len; i++){

_ul=_ul+'<li>'+i+'</li>';

}

_ul=_ul+'</ul>';

$('div.ico').append(_ul);

var _ico=$('.ico li');

//划过数字

_ico.mouseover(function(){

_index=_ico.index(this);

_img.filter(':visible').fadeOut(300,function(){

_img.eq(_index).fadeIn(300);

})

$(this).addClass('high').siblings().removeClass('high');

}).eq(0).mouseover();

//自动渐变

_moving=setInterval(autoShow,2000);

_img.hover(function(){clearInterval(_moving)},function(){

_moving=setInterval(autoShow,2000);

})

function autoShow(){

_index++;

if(_index==_len) _index=0;

_ico.eq(_index).trigger('mouseover');

};

});

</script>

</head>

<body>

预览效果时左下角会提示错误,而且看不到效果,刷新一下就可以看到效果了;当然,在实际使用中,不会出现这样的问题。<br>

<>

<div>

<img src="http://www.jb51.netimages/m02.jpg" title="demo" alt="demo">

<img src="http://www.jb51.netimages/m01.jpg" title="demo" alt="demo">

<img src="http://www.jb51.netimages/m03.jpg" title="demo" alt="demo">

<img src="http://www.jb51.netimages/m04.jpg" title="demo" alt="demo">

<img src="http://www.jb51.netimages/m05.jpg" title="demo" alt="demo">

<div></div>

</div>

</body>

</html>

希望本文所述对大家的jQuery程序设计有所帮助。

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新Javascript教程学习
热门Javascript教程学习
编程开发子分类