javascript - How to get this code to run in jsFiddle? -
how run code in jsfiddle? original code adam khoury's site @ http://www.developphp.com/view.php?tid=1262
i've experimented , able button show , canvas outline can not object animate left right when button clicked.
here effort run in jsfiddle at...
http://jsfiddle.net/tn8xc/
function draw(x,y){ var canvas = document.getelementbyid('canvas'); var ctx = canvas.getcontext('2d'); ctx.save(); ctx.clearrect(0,0,550,400); ctx.fillstyle = "rgba(0,200,0,1)"; ctx.fillrect (x, y, 50, 50); ctx.restore(); x += 1; var looptimer = settimeout('draw('+x+','+y+')',30); }
thanks help.
jsfiddle's default settings have javascript run onload
, or after html loads.
this works cases, except when utilize on*
attribute execute js inline, because js hasn't loaded, can't access variables , methods.
you need alter onload
to no wrap - in <head>
in left sidebar @ top: places js in <script>
tags in head. head loads before else (whatever set in html area), when utilize onclick
attribute reference draw()
function, has been defined.
you can utilize no wrap - in <body>
because js still placed before rest of html, placing in head
should serve in cases.
had checked console, have seen referenceerror: can't find variable: draw
, have told js hadn't loaded before tried access draw()
.
demo
javascript css html5 animation
No comments:
Post a Comment