It is really cool to run Go code in the browser. GopherJS is a compiler from
Go to JavaScript, which makes this possible.
In this post, we will give an example of DOM manipulation in Go program.
This example shows how to write a draggable/movable HTML element. This example
is ported from Dart draggable/movable element [5].
If you are not familiar with basic DOM manipulation in Go, read the
posts in GopherJS DOM Example series first.
The basic idea is that we bind onmousedown event handler to the draggable
element. In the onmousedown event handler, we bind onmousemove and onmouseup
event handler to document object. In the onmousemove event handler, we
calculate the movement and change the CSS property of the draggable element to
make it move. In the onmouseup event handler, we remove the onmousemove and
onmouseup event handler from document object.