Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
352 views
in Technique[技术] by (71.8m points)

这个js效果怎麽做到的呢?通常怎麽称呼?

在visual studio code的官方首页看到这个效果

clipboard.png

看了一下它的页面代码,是用一个div.mask先做了上下模煳的效果,裡面在放<ul>和数个<li>做为每个文字的项目,但是它在ul那有写个 reactroot ,我试着将chrome的javascript功能关起来后那效果确实不能跑了。

.home .getting-started .mask {
    background: linear-gradient(180deg,#fff,hsla(0,0%,100%,0),hsla(0,0%,100%,0),#fff);
    z-index: 5;
    height: 100%;
    width: 100%;
    position: absolute;
    left: -20px;
}

也就是说这应该不是纯CSS的效果,而是利用js操作dom得出的效果,但具体怎麽实现我没办法从reac转es5的javascript代码段看出来,想请问大家这效果具体怎麽实现呢? 用纯 javascript或jquery都行,或者是设计思路。

谢谢各位


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

瞎写的 用了setInterval以及transition
css:

 <style>
        *{
            margin: 0;
            padding: 0;
        }
        li{
            list-style-type: none;
        }
        .home{
            box-sizing: border-box;
            padding: 100px;
            width: 650px;
            display: flex;
            margin: auto;
        }
       .home .title{
         height: 300px;
           width: 500px;
        }
        .title h2{
            line-height: 300px;
        }
        .home .ul-list{
            height: 300px;
            width: 500px;
            position: relative;
        }
        .mask{
            background: linear-gradient(180deg,#fff,hsla(0,0%,100%,0),hsla(0,0%,100%,0),#fff);
            z-index: 5;
            height: 100%;
            width: 100%;
            position: absolute;
            left: -20px;
        }
        .list{
            height: 100%;
            overflow: hidden;
            position: relative;
        }
        ul{
            height: 100%;
            width: 100%;
            position: absolute;
            top: 0;
            transition: top 1s;
            box-sizing: content-box;
            padding-right: 20px;

            padding-left: 0;
            list-style: none;
            margin-bottom: 0;
        }
        ul li{
            font-size: 30px;
            height: 40px;
        }
    </style>

html:

<body>
<div class="home">
    <div class="title">
   <h2>VS Code for</h2>
    </div>
    <div class="ul-list">
        <div class="mask">

        </div>
        <div class="list">
            <ul id="list">
                <li>111</li>
                <li>222</li>
                <li>333</li>
                <li>444</li>
                <li>555</li>
                <li>666</li>
                <li>777</li>
                <li>888</li>
                <li>999</li>
                <li>10000</li>
                <li>111</li>
                <li>222</li>
                <li>333</li>
                <li>444</li>
                <li>555</li>
                <li>666</li>
                <li>777</li>
                <li>888</li>
                <li>999</li>
                <li>10000</li>
            </ul>
        </div>
    </div>

</div>
</body>

js:

<script>
    var timing=null;
      timing=setInterval(function () {
          addTop();
         console.log(parseInt($("#list").css('top')))
          if (parseInt($("#list").css('top'))<=-510){
//              clearInterval(timing)
              $("#list").css("top",0+'px')
          }
      },1500)
    addTop=function () {
        var num =parseInt($("#list").css('top'))
        $("#list").css("top",(num-30)+'px')
    }

</script>

clipboard.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...