输出没有生成...... [英] The output is not generated...

查看:102
本文介绍了输出没有生成......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是代码>>>>

Here is the code>>>>

<!doctype html>
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css -->
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<style>
    body{ background-color: ivory; }
    canvas{border:1px solid red;}
</style>
<script>

        var canvas = document.getElementById("canvas");
        var ctx = canvas.getContext("2d");

        function star(ctx, x, y, r, p, m)
        {
            ctx.save();
            ctx.beginPath();
            ctx.translate(x, y);
            ctx.moveTo(0, 0 - r);
            for (var i = 0; i < p; i++)

            {

                ctx.rotate(Math.PI / p);

                ctx.lineTo(0, 0 - (r * m));

                ctx.rotate(Math.PI / p);

                ctx.lineTo(0, 0 - r);

            }

            ctx.fill();

            ctx.restore();

        }

        star(ctx, 100, 100, 90, 5, 0.5);



</script>
</head>
<body>
    <canvas id="canvas" width=300 height=300></canvas>
</body>
</html>





在输出中我没有得到明星......



In output i didn't get the star...

推荐答案

那是因为没有调用 star 函数。您应该在文档就绪事件中运行。



演示 - [演示]在画布上显示星星 [ ^ ]
That is because star function is not invoked. You should run that in document ready event.

Demo - [Demo] Display Star on Canvas[^]


脚本元素移至 body ,使其成为 body 元素的子元素。你会观察到这颗恒星。问题已经解决了。



现在阅读有关使用脚本元素的内容并考虑一下。



-SA
Move your script element to body, make it a child of the body element. You will observe the star. The problem is solved.

Now read about using script element and think about it.

—SA


这篇关于输出没有生成......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆