javascript - Can't draw a straight line to a specified position on a div?
欧阳克
欧阳克 2017-06-26 10:52:43
0
2
747
<p id="myCanvas"></p>
#myCanvas {
    width:100px;height:100px;
    border: 1px dashed black;
}

        var canvas = document.getElementById("myCanvas");
        var context = canvas.getContext("2d");
        context.lineWidth = 10;
        context.moveTo(0, 50);
        context.lineTo(50, 50);
        context.stroke();
        
        canvas的用法是否仅仅对canvas标签起作用?
        上面的代码无法在普通p内绘制直线,将p修改成canvas就可以。
        

欧阳克
欧阳克

温故而知新,可以为师矣。 博客:www.ouyangke.com

reply all(2)
我想大声告诉你

How can p use canvas api? Replace p with canvas element

曾经蜡笔没有小新

Canvas and p are not the same thing at all. You definitely can’t use canvas’s API!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!