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>

  • 相关阅读:
    【源码学习之spark core 1.6.1 standalone模式下的作业提交】
    【源码学习之spark streaming 1.6.1 】
    spark udf 初识初用
    spark 累加历史 + 统计全部 + 行转列
    spark 都用了哪些开源东东
    kafka 官方示例代码--消费者
    104. 二叉树的最大深度
    237. 删除链表中的节点
    Leetcode-167. Two Sum II
    Leetcode-215. Kth Largest Element in an Array
  • 原文地址:https://www.cnblogs.com/xutongbao/p/9924832.html
Copyright © 2011-2022 走看看