[GopherJS] Element Position (Offset)
source link: http://siongui.github.io/2016/03/25/gopherjs-element-position-offset/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
[GopherJS] Element Position (Offset)
March 25, 2016
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:
[4][AngularJS] Get Element Offset (Position)
[5]JavaScript DOM Element Position (Scroll Position Included)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK