美文网首页
Js-旋转木马

Js-旋转木马

作者: MGd | 来源:发表于2017-03-23 13:35 被阅读30次
  • HTML部分:
<div class="all"id=all>
    <ul id="oul">
        <li>![](../images/slidepic1.jpg)</li>
        <li>![](../images/slidepic2.jpg)</li>
        <li>![](../images/slidepic3.jpg)</li>
        <li>![](../images/slidepic4.jpg)</li>
        <li>![](../images/slidepic5.jpg)</li>
    </ul>
    <div class="bottom" id="bottom">
        <span class="left"></span>
        <span class="right"></span>
    </div>
</div>
  • CSS部分:
 *{
       margin:0;
       padding:0;
       border:none;
       }
        .all{
            width: 1200px;
            height: 500px;
            margin: 150px auto;
            position: relative;
        }
        ul li {
            list-style: none;
            position: absolute;
            top:0;
            left:200px;
        }
        .bottom{
            opacity: 0;
        }
        .left,.right{
            position: absolute;
            width: 76px;
            height: 112px;
            top: 50%;
            margin-left:-38px;
            z-index: 99;
            cursor: pointer;
        }
        .left{
            left: 0;
            background: url("../images/prev.png");
        }
        .right{
            right: 0;
            background:url("../images/next.png");
        }
  • JS部分:
 window.onload = function () {
        //获取标签
        var all = document.getElementById("all");
        var oul = document.getElementById("oul");
        var bottom = document.getElementById("bottom");
        var lis = oul.children;
        //触碰大盒子显示两个箭头
        all.onmouseover = function () {
            buffer(bottom,{opacity:1})
        }
        all.onmouseout = function () {
            buffer(bottom,{opacity:0.01})
        }
        //设置各个图片的对应位置
        var json = [
            {   //  1
                width:400,
                top:20,
                left:50,
                opacity:0.2,
                z:2
            },
            {  // 2
                width:600,
                top:70,
                left:0,
                opacity:0.8,
                z:3
            },
            {   // 3
                width:800,
                top:100,
                left:200,
                opacity:1,
                z:4
            },
            {  // 4
                width:600,
                top:70,
                left:600,
                opacity:0.8,
                z:3
            },
            {   //5
                width:400,
                top:20,
                left:750,
                opacity:0.2,
                z:2
            }
        ]
        //抽取函数设置各个图片的属性
        var flag = true;
        function change(){
            //遍历每个li取出每一个数据
            for(var i=0;i<lis.length;i++){
                var item = json[i];
      //确定图片的位置
                buffer(lis[i],{width:item.width,left:item.left,top:item.top,opacity:item.opacity,zIndex:item.z},function(){
                    flag = true;
                });
            }
        }
        change();
//点击span设置对应的动画变化
        for(var i = 0;i<bottom.children.length;i++){
            var mySpan = bottom.children[i];
            mySpan.onclick = function () {
                if(flag == true){
                    if(this.className == "left"){
                        json.push(json.shift());
                        flag = false;
                        change();
                    }else if(this.className == "right"){
                        json.unshift(json.pop());
                        flag = false;
                        change();
                    }
                }
            }
        }
    }

相关文章

  • Js-旋转木马

    HTML部分: CSS部分: JS部分:

  • 私房故事【4】:旋转木马的爱情

    旋转木马的传说:有人说旋转木马是见证两个相爱的人的爱情游戏,只要两个真心相爱的人同时坐在旋转木马上,木马就会载着他...

  • 2019-06-21

    ️旋转木马上

  • 。。

    想坐旋转木马

  • 《人生旋转木马》

    风来了, 沉寂的木马,旋转起来; 风走了, 木马依旧旋转着,借着惯性; 就好像风一直在。 风来,风去, 旋转木马,...

  • 《余情》游乐场

    木马很听话,在旋转着 听风声,在旋转木马上 小孩开心的笑着 几米之外的情侣犹豫着要不要坐上去 有人静静看着旋转木马...

  • 旋转木马

    不喜欢玩旋转木马,有人问为什么?刚开始我也不知道,后来才慢慢明白,因为它是个残忍的游戏,彼此追逐着,却永远追不上那...

  • 旋转木马

    追赶你的脚步, 触手可及, 却措手不及。 你的孤单背影, 挡住我的美丽风景, 或许不该在你身后, 那样便可不再和你错过。

  • 旋转木马

  • 旋转木马

    耳边仅有风的呼啸和凌厉的目光,世界却在慢慢缩小,仅剩下一个旋转木马,灯光温和,如梦似幻。我的手在他的手心里安稳...

网友评论

      本文标题:Js-旋转木马

      本文链接:https://www.haomeiwen.com/subject/xyjonttx.html