YPos += (el.offsetTop - el.scrollTop + el.clientTop) ![]() XPos += (el.offsetLeft - el.scrollLeft + el.clientLeft) YPos += (el.offsetTop - yScroll + el.clientTop) XPos += (el.offsetLeft - xScroll + el.clientLeft) deal with browser quirks with body/window/document and page scroll Helper function to get an element's exact position Window.addEventListener("resize", updatePosition, false) ![]() Window.addEventListener("scroll", updatePosition, false) deal with the page getting resized or scrolled The full code for making this example work looks as follows: var canvas = document.querySelector("#m圜anvas") Ĭanvas.addEventListener("mousemove", setMousePosition, false) Ĭontext.clearRect(0, 0, canvas.width, canvas.height) To kick your canvas skills up a few notches, everything you see here and more (with all its casual clarity!) is available in both paperback and digital editions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |