jquery漸隱漸顯的圖片幻燈閃爍切換實現方法_jquery

來源:互聯網
上載者:User

本文執行個體講述了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">
<!--把下面代碼加到<head>與</head>之間-->
<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>
<!--把下面代碼加到<body>與</body>之間-->
<div class="slides">
 <img src="/images/m02.jpg" title="demo" alt="demo">
 <img src="/images/m01.jpg" title="demo" alt="demo">
 <img src="/images/m03.jpg" title="demo" alt="demo">
 <img src="/images/m04.jpg" title="demo" alt="demo">
 <img src="/images/m05.jpg" title="demo" alt="demo">
 <div class="ico"></div>
</div>
</body>
</html>

希望本文所述對大家的jQuery程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.