zoukankan      html  css  js  c++  java
  • Canvas 通过改变渐变线的起始点做飞线效果

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Canvas 通过改变渐变线的起始点做飞线效果</title>
    </head>
    
    <body>
        <canvas id="myCanvas" width="700" height="700" style="border:1px solid #d3d3d3;">
            您的浏览器不支持 HTML5 canvas 标签。
        </canvas>
        <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        var start = 0;
        function auto() {
            ctx.beginPath();
            ctx.moveTo(0, 100);
            ctx.lineTo(700, 100);
            var grd = ctx.createLinearGradient(start, 0, start + 200, 0);
            grd.addColorStop(0, "#5BC0DE");
            grd.addColorStop(0.5, "#ffff00");
            grd.addColorStop(1, "#5BC0DE");
            ctx.lineWidth = 5;
            ctx.strokeStyle = grd;
            ctx.stroke();
            ctx.closePath();
            if (start >= 700) {
                start = 0;
            } else {
                start = start + 50;
            }
            setTimeout(function() {
                auto();
            }, 100);
        }
        auto();
        </script>
    </body>
    </html>

    竖版:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <title>Canvas 通过改变渐变线的起始点做飞线效果</title>
    </head>
    
    <body>
        <canvas id="myCanvas" width="700" height="700" style="border:1px solid #d3d3d3;">
            您的浏览器不支持 HTML5 canvas 标签。
        </canvas>
        <script>
        var c = document.getElementById("myCanvas");
        var ctx = c.getContext("2d");
        var start = 0;
        function auto() {
            ctx.beginPath();
            ctx.moveTo(100, 0);
            ctx.lineTo(100, 700);
            var grd = ctx.createLinearGradient(0, start, 0, start + 200);
            grd.addColorStop(0, "#5BC0DE");
            grd.addColorStop(0.5, "#ffff00");
            grd.addColorStop(1, "#5BC0DE");
            ctx.lineWidth = 5;
            ctx.strokeStyle = grd;
            ctx.stroke();
            ctx.closePath();
            if (start >= 700) {
                start = 0;
            } else {
                start = start + 50;
            }
            setTimeout(function() {
                auto();
            }, 100);
        }
        auto();
        </script>
    </body>
    </html>

  • 相关阅读:
    假脱机技术
    HTTP报文
    字符串转换成浮点数的方法
    表变量与临时表空间
    规范浮点数
    什么是批处理
    浅谈性能测试、压力测试和负载测试
    关于CSDN的一个安全漏洞
    HttpWatch7.0测试工具
    vbscript能做什么
  • 原文地址:https://www.cnblogs.com/xutongbao/p/9924832.html
Copyright © 2011-2022 走看看