File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ Returns **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer
50
50
51
51
### scrollLeft
52
52
53
- Return amount of px scrolled from the top of the document
53
+ Return amount of px scrolled from the left of the document
54
54
55
55
Returns ** [ Number] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number ) ** scroll left value in px
56
56
@@ -63,3 +63,13 @@ Get the offset top of any DOM element
63
63
- ` el ` ** [ HTMLElement] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element ) ** the element we need to check
64
64
65
65
Returns ** [ Number] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number ) ** the element y position in px
66
+
67
+ ### elementOffsetLeft
68
+
69
+ Get the offset left of any DOM element
70
+
71
+ ** Parameters**
72
+
73
+ - ` el ` ** [ HTMLElement] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element ) ** the element we need to check
74
+
75
+ Returns ** [ Number] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number ) ** the element x position in px
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ export function scrollTop() {
85
85
}
86
86
87
87
/**
88
- * Return amount of px scrolled from the top of the document
88
+ * Return amount of px scrolled from the left of the document
89
89
* @returns { Number } scroll left value in px
90
90
*/
91
91
export function scrollLeft ( ) {
@@ -104,4 +104,13 @@ export function scrollLeft() {
104
104
*/
105
105
export function elementOffsetTop ( el ) {
106
106
return max ( scrollTop ( ) + el . getBoundingClientRect ( ) . top )
107
+ }
108
+
109
+ /**
110
+ * Get the offset left of any DOM element
111
+ * @param { HTMLElement } el - the element we need to check
112
+ * @returns { Number } the element x position in px
113
+ */
114
+ export function elementOffsetLeft ( el ) {
115
+ return max ( scrollLeft ( ) + el . getBoundingClientRect ( ) . left )
107
116
}
Original file line number Diff line number Diff line change @@ -36,4 +36,10 @@ describe('Bianco viewport', function() {
36
36
assert . equal ( typeof viewport . elementOffsetTop ( div ) , 'number' )
37
37
assert . ok ( notNaN ( viewport . elementOffsetTop ( div ) ) )
38
38
} )
39
+
40
+ it ( 'elementOffsetLeft is a number' , function ( ) {
41
+ const div = document . createElement ( 'div' )
42
+ assert . equal ( typeof viewport . elementOffsetLeft ( div ) , 'number' )
43
+ assert . ok ( notNaN ( viewport . elementOffsetLeft ( div ) ) )
44
+ } )
39
45
} )
You can’t perform that action at this time.
0 commit comments