Wednesday, June 15, 2022

A hard to work code in JS

 This code have a not need complexity, is only good to learn events, specifically onload, but is very bad sew to learn canvas, is good to apply something like an function that says the time nd day when the user get in the page

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8"/>
    <title>Canvas tutorial</title>
    <script>
      function draw() {
        const canvas = document.getElementById('tutorial');
        if (canvas.getContext) {
          const ctx = canvas.getContext('2d');
        }
      }
    </script>
    <style>
      canvas { border: 1px solid black; }
    </style>
  </head>
  <body onload="draw();">
    <canvas id="tutorial" width="150" height="150"></canvas>
  </body>
</html>

So isn't need create an function to run the canvas, you apply directly, doing that way you had to create the event listener on load of the page, if write out of that function will have the canvas there but with the function you have to put the listener onload of the page, but is an example of how to use the onload, that is very good to run codes that want to run an data that is refresh, and will renew to everytime the page be loaded, like good day good afternoon good night depending of the time of the day our site is acesseced. Rute Bezerra de Menezes Gondim









No comments:

Post a Comment