图片轮播图之手风琴特效

最好就是把图片设置成同样大小代码如下:

<!DOCTYPE html>
<html>
<head>
    <title>图片广告初级6</title>
    <meta charset="utf-8">
    <style>
        *{padding: 0;
            margin:0;}

        ul {
            list-style: none;
        }

        div {
            width: 1200px;
            height: 460px;
            margin: 50px auto;
            border: 1px solid #ccc;
            overflow: hidden;
        }

        div li {
            width: 240px;
            height: 460px;
            float: left;

        }

        div ul {
            width: 1200px;
        }


    </style>

</head>
<body>
<div id="dv">
    <ul>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>
<script>
    function getStyle(element,attr)
    {
        return window.getComputedStyle?window.getComputedStyle(element,null)[attr]:element.currentStyle[attr]||0;
    }
    function animate(element,json,fn)
    {
        clearInterval(element.timeId);
        element.timeId=setInterval(function () {
            var flag=true;//默认全部到达目标
            for(var attr in json)
            {
                //判断这个attr是不是opacity
                if (attr=="opacity")
                {
                    var current=getStyle(element,attr)*100;
                    var target=json[attr]*100;
                    //移动步数
                    var step=(target-current)/10;
                    step=step>0?Math.ceil(step):Math.floor(step);
                    current+=step;
                    element.style[attr]=current/100;
                }
                //判断这个attr是不是zIndex
                else if(attr=="zIndex")
                {
                    element.style[attr]=json[attr];
                }
                else
                {
                    var current=parseInt(getStyle(element,attr));
                    var target=json[attr];
                    //移动步数
                    var step=(target-current)/10;
                    step=step>0?Math.ceil(step):Math.floor(step);
                    current+=step;
                    element.style[attr]=current+"px";

                }
                if(current!=target)
                {
                    flag=false;
                    
                }
            }
            if(flag){
                clearInterval(element.timeId);
                if(fn){
                    fn();
                }
            }
        },20);
    }
    var list=document.getElementById("dv").getElementsByTagName("li");
    for (var i=0;i<list.length;i++)
    {
        list[i].style.background = "url(sfqq" + (i + 1) + ".jpg)";
        //鼠标进入
        list[i].onmouseover = mouseoverHandle;
        //鼠标离开
        list[i].onmouseout = mouseoutHandle;
    }
    //进入
    function mouseoverHandle() {
        for (var j = 0; j < list.length; j++) {
            animate(list[j], {"width": 100,"opacity":0.3});//动画效果
        }
        animate(this, {"width": 800,"opacity":1});
    }
    //离开
    function mouseoutHandle() {
        for (var j = 0; j < list.length; j++) {
            animate(list[j], {"width": 240,"opacity":1});//动画效果
        }
    }
</script>
</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值