zoukankan      html  css  js  c++  java
  • 滚动区块的透明度渐变(遮罩)

    闲话不说,先看效果:

    代码实现:

    <div class="rollingBlock">
        <div class="mask"></div>
        <ul class="list">
            <li>01</li>
            <li>02</li>
            <li>03</li>
            <li>04</li>
            <li>05</li>
            <li>06</li>
            <li>07</li>
            <li>08</li>
            <li>09</li>
            <li>10</li>
        </ul>
    </div>
    HTML
    div.rollingBlock{
        position: relative;
        box-sizing: border-box;
        width: 800px;
        height: 600px;
        background-color: #021019;  
        border-radius: 2px;
        overflow: hidden;
        transition: background-color  0.5s;
        -webkit-transition: background-color 0.5s;
        -moz-transition: background-color 0.5s;
        -o-transition: background-color 0.5s;
        -ms-transition: background-color 0.5s; 
    }
    div.rollingBlock div.mask{
        position: absolute;
        z-index:999;
        top: 0;
        left: 0;
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        background: -webkit-gradient(linear, 0 0, 0 100%, from(rgba(2,16,25,1)), to(rgba(2,16,25,0)));
        background: -moz-linear-gradient(top, rgba(0,0,0, 1), rgba(255, 255, 255, 0));
        background: -o-linear-gradient(top,  rgba(0,0,0, 1), rgba(255, 255, 255, 0));
        background: -ms-linear-gradient(top,  rgba(0,0,0, 1), rgba(255, 255, 255, 0));
        background: linear-gradient(top,  rgba(0,0,0, 1), rgba(255, 255, 255, 0));
    }
    div.rollingBlock div.mask:hover{
        background: transparent;
    }
    div.rollingBlock ul{
        position: absolute;
        left: 22px;
        top: 0;
        width: 100%;
    }
    div.rollingBlock li{
        box-sizing: border-box;
        width: 100%;
        height: 40px;
       text-align: center;
        padding: 0 10px 0 1px;
        margin-top: 6px;
        line-height: 40px;
        background-color: rgba(0,0,0,0.5);
        border-radius: 2px;
    }
    CSS
    $("div.rollingBlock").hover(function(){
        clearInterval(time);
    }, function() {
        roll();
    });
    var time = null;
    var control = false;
    function roll() {
        clearInterval(time);
        time = setInterval(function() {
            // var top = Number.parseInt(getStyle(oUl, 'top'));
            var top = ul.position().top;
            ul.animate({top:top-46 + 'px'}, "slow",function() {
                top = Number.parseInt(getStyle(oUl, 'top'));
                var obj = ul.children().first().remove();
                ul.append(obj);
                ul.css("top",top+46 + 'px');
            } );
        }, 2000);
    }
    roll();
    JavaScript

     注意遮罩的rgba()色彩要与盒子的背景色一致

  • 相关阅读:
    Solaris 默认Shell 修改
    关系数组
    文件描述符 文件操作 <> open 文件句柄
    IO 双引号 输出 输入
    第五章答案
    子例程 subroutine
    钻石操作符
    花括号的使用 printf %${width}s , 否则会 去找 $widths
    print reverse <> 是打印全部的文件内容 ?
    hihoCoder#1239 Fibonacci
  • 原文地址:https://www.cnblogs.com/lianchenxi/p/10058832.html
Copyright © 2011-2022 走看看