File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
22 - Follow Along Link Highlighter Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 27
27
28
28
< script >
29
29
// 👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀
30
+ const triggers = document . querySelectorAll ( 'a' ) ;
31
+ const highlight = document . createElement ( 'span' ) ;
32
+ highlight . classList . add ( 'highlight' ) ;
33
+ document . body . append ( highlight ) ;
34
+
35
+ function highlightLink ( ) {
36
+ const linkCoords = this . getBoundingClientRect ( ) ;
37
+ const coords = {
38
+ width : linkCoords . width ,
39
+ height : linkCoords . height ,
40
+ top : linkCoords . top + window . scrollY ,
41
+ left : linkCoords . left + window . scrollX ,
42
+ }
43
+ console . log ( this , linkCoords )
44
+ highlight . style . width = `${ coords . width } px` ;
45
+ highlight . style . height = `${ coords . height } px` ;
46
+ highlight . style . transform = `translate(${ coords . left } px, ${ coords . top } px` ;
47
+
48
+ //fix the offset of window.scrollY
49
+ }
50
+
51
+ triggers . forEach ( a => a . addEventListener ( 'mouseenter' , highlightLink ) ) ;
30
52
</ script >
31
53
</ body >
32
54
</ html >
You can’t perform that action at this time.
0 commit comments