×

canvas应用:七彩太阳照射光晕效果

作者:andy0012021.07.12来源:Web前端之家浏览:171评论:0
关键词:canvas

canvas应用:七彩太阳照射光晕效果。一起来看下DEMO:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>canvas应用:七彩太阳照射光晕效果 | Web前端之家www.jiangweishan.com</title>
    <script>
        window.onload=function(){
            var canvas=document.getElementById('canvas');
            var cx=canvas.getContext("2d");
            cx.fillStyle='pink';
            cx.strokeStyle='pink';
            for(var i=0;i<10;i++){
                var g=cx.createLinearGradient(0,0,290,290);
                g.addColorStop(0,'rgba(255,0,0,1)');
                g.addColorStop(0.1,'rgba(255,0,0,0.5)');
                g.addColorStop(0.2,'rgba(255,165,0,0.4)');
                g.addColorStop(0.4,'rgba(205,255,0,0.5)');
                g.addColorStop(0.6,'rgba(230,145,0,0.5)');
                g.addColorStop(0.8,'rgba(0,127,255,0.5)');
                g.addColorStop(0.9,'rgba(100,200,205,0.9)');
                g.addColorStop(1,'rgba(0,255,255,0.5)');;
                cx.fillStyle=g;
                cx.beginPath();
                cx.arc(i*25,i*25,i*10,0,Math.PI*2,true);
                cx.closePath();
                cx.fill();
            }
        }
    </script>
</head>
<body>
    <canvas id="canvas" width="600px" height="600px" style="background-color: #ccc;"></canvas>
    
</body>
</html>

预览下,看下效果。

温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/canvas20210712a1.html

网友评论文明上网理性发言 已有0人参与

发表评论:

最新留言

  • 土工膜

    资深程序员就是不简单...

  • 大吨位油缸

    谷歌浏览器使用起来很快,没有乱七八糟的插件。www.sdlyxt.com...

  • Web前端之家

    可以加Q群...

  • 访客

    JS点击锚点实现平滑滚动能写一个备注呗,有点看不懂,谢谢...

  • alice

    试用了下,vee-validate挺好用的!...

  • 访客

    封装思路跟原生javascript基本差不多。...

  • qianduan

    这个跟H5做的很像,看上去用react实现起来要简单些。...

  • qianduan

    YYDS的文章,收藏了。...

首页|JavaScript|HTML|HTML4|HTML5|CSS3|开发工具|性能优化|移动开发|前端教程|性能优化|开发工具|酷站欣赏|UI设计|前端教程

Copyright © 2021 Web前端之家(www.jiangweishan.com) 版权所有 All Rights Reserved.
粤ICP备12067512号-1

Copyright Your WebSite.Some Rights Reserved.

Powered By Z-BlogPHP 1.6.7 Valyria