再个图片 Javascript 仿Flash图片轮翻

<style type="text/css">
 #album{
    position:relative;
    width:950px;
    height:90px;
    border:0px;
    overflow:hidden;
  }
  #album dt {
    margin:0;
    padding:0;
    width:950px;
    height:90px;
    overflow:hidden;
  }
  #album img {
    border:0px;
  }
  #album dd {
    position:absolute;
    right:0px;
    bottom:10px;
  }
  #album a {
    display:block;
    float:left;
    margin-right:10px;
    width:15px;
    height:15px;
    line-height:15px;
    text-align:center;
    text-decoration:none;
    color:#808080;
    background:transparent url(/images/o_button.gif) no-repeat -15px 0;
  }
  #album a:hover ,#album a.hover{
    color:#F8F8F8;
    background-position:0 0;
  }
</style>

<dl id="album">
  <dt>
    <img id="index1" src="http://www.rcles.com/data/attachment/forum/201205/17/234444nybk1ykdqgkykzm8.png  " />
    <img id="index2" src="http://www.rcles.com/data/attachment/forum/201205/17/234445h2ad5fo30hwsh023.png " />
  </dt>
  <dd>
    <a href="#index1">1</a><a href="#index2">2</a>
  </dd>
</dl>
<script type="text/javascript">
  function imageRotater(id){
    var cases = "",
    album = document.getElementById(id),
    images = album.getElementsByTagName("img"),
    links = album.getElementsByTagName("a"),
    dt = album.getElementsByTagName("dt")[0],
    length = images.length,
    aIndex = 1,
    aBefore = length;
    for(var i=0;i< length;i++){
      cases += images[i].id + ':"'+images[i].getAttribute("src")+'",'
    }
    images[0].style.cssText = "position:absolute;top:0;left:0;";//修正图片位置错误
    var tip = document.createElement("dd");
    tip.style.cssText = "position:absolute;bottom:0;height:20px;width:40px;padding:10px;color:#fff;background:#fff;";
    album.insertBefore(tip,dt.nextSibling);
    if(!+"\v1"){
      tip.style.color = "#369";
      tip.style.filter = "alpha(opacity=67)"
    }else{
      tip.style.cssText += "background: rgba(164, 173, 183, .65);"
    }
    cases = eval("({"+cases.replace(/,$/,"")+"})");
    for(var i=0;i<length;i++){
      links[i].onclick = function(e){
        e =e || window.event;
        var index = this.toString().split("#")[1];
        aIndex = index.charAt(index.length-1);//☆☆☆☆
        images[0].src = cases[index];
        tip.innerHTML = images[aIndex -1].getAttribute("alt");
          !+"\v1" ?(e.returnValue = false) :(e.preventDefault());
      }
    }
    var prefix = images[0].id.substr(0,images[0].id.length -1);
    (function(){
      setTimeout(function(){
        if(aIndex > length){
          aIndex = 1;
        }
        images[0].src = cases[prefix+aIndex];
        tip.innerHTML = images[aIndex -1].getAttribute("alt");
        tip.style.bottom = "-40px";
        links[aBefore-1].className = "";
        links[aIndex-1].className = "hover";
        aBefore = aIndex;
        aIndex++;
        move(tip);
        setTimeout(arguments.callee,1500)
      },1500)
    })()
    var move = function(el){
      var begin = parseFloat(el.style.bottom),
      speed = 1;
      el.bottom = begin;
      (function(){
        setTimeout(function(){
          el.style.bottom = el.bottom + speed + "px";
          el.bottom += speed;
          speed *= 1.5;//下一次移动的距离
          if(el.bottom >= 0){
            el.style.bottom = "0px";
          }else{
            setTimeout(arguments.callee,23);
          }
        },25)
      })()
    }
  }
  window.onload = function(){
    try{document.execCommand("BackgroundImageCache", false, true);}catch(e){};
    imageRotater("album");
  }
</script>


我网站www.rcles.com首页的两个图片做的flash,以前我一直用图片跑马灯,我网站是dz2的,这就造成了DIY设置的失效,而我用这个仿flash图片轮翻却可以实现。

原文:http://www.codefans.net/jscss/code/1652.shtml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值