[GopherJS] Element Position (Offset)
Get DOM element position (offset) via GopherJS.
Install GopherJS first:
$ go get -u github.com/gopherjs/gopherjs
Source code for element position (offset) via getBoundingClientRect:
package gojs
import "github.com/gopherjs/gopherjs/js"
type DOMClientRect struct {
Bottom string
Height string
Left string
Right string
Top string
Width string
}
func GetPosition(elm *js.Object) DOMClientRect {
rect := elm.Call("getBoundingClientRect")
return DOMClientRect{
Bottom: rect.Get("bottom").String(),
Height: rect.Get("height").String(),
Left: rect.Get("left").String(),
Right: rect.Get("right").String(),
Top: rect.Get("top").String(),
Width: rect.Get("width").String(),
}
}
This comes from answer of Stack Overflow question [3].
Tested on: Ubuntu Linux 15.10, Go 1.6.
References:
[1] | GopherJS - A compiler from Go to JavaScript (GitHub, GopherJS Playground, ) |
[2] | GitHub - siongui/gopherjs-utils: useful collections of utilites (functions) for front end (browser) development via GopherJS |
[3] |
[4] | [AngularJS] Get Element Offset (Position) |
[5] | JavaScript DOM Element Position (Scroll Position Included) |