javascript图片变化的效果

本文介绍了一种使用JavaScript实现的图片轮播效果,利用CSS滤镜实现图片过渡,并结合setTimeout函数控制图片切换时间。但存在点击链接切换图片时速度过快的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

javascript图片变化的效果,也算是今天学到的一点小知识

 

 

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
    
var numAD=0;
  
var imgAD = new Array();//存储图片的src地址为数组。
  imgAD[0= "images/1.jpg";
  imgAD[
1= "images/2.jpg";
  imgAD[
2= "images/3.jpg";
  imgAD[
3= "images/4.jpg";
    imgAD[
4= "images/5.jpg";
    
var dotime=5000;
  
function setTransition(){
   
if(document.all){
      u.filters.revealTrans.Transition
=23;//Math.floor(Math.random()*23);
        u.filters.revealTrans.Duration=4;
      u.filters.revealTrans.apply();
   }

  }

  
function playTransition(){
   
if(document.all){
      u.filters.revealTrans.play();
   }

  }

  
function nextAD(){
   setTransition();
   document.u.src
=imgAD[numAD];
   playTransition();
   
if(numAD >= imgAD.length-1){
      numAD
=0;
   }
else{
      numAD
++;
   }

   window.setTimeout(
"nextAD()",dotime);
  }

function ad_clok(v)
{
    
this.numAD=v-1;
    
this.dotime=20000;
    nextAD();
}

</script>
<body onload="nextAD()">
<div id="" style="width:200px;">
<img src="images/1.jpg" width="200" height="200" border="0"name="u" id="u" style="FILTER: revealTrans(duration=4,transition=20)" />
<div id="" style="width:100%"><href="javascript:ad_clok(1)">1</a> <href="javascript:ad_clok(2)">2</a> <href="javascript:ad_clok(3)">3</a> <href="javascript:ad_clok(4)">4</a>
</div>
</div>
</body>
</html>

 

现在很多网站都有这种作为图片新闻展示的js效果了,不是什么新东西。这里面包含的主要两个东西就是:对css滤镜的使用和js的setTimeout()函数。不过呢后来发现一个问题,当通过下面的1,2,3,4连接来显示图片的时候图片变换非常快根本没达到设定的20秒,貌似window.setTimeout("nextAD()",dotime);里面的dotime失效了没气作用,困扰了我很久,希望达人恩解答哦,再见!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值