File tree Expand file tree Collapse file tree 1 file changed +23
-2
lines changed
22 - Follow Along Link Highlighter Expand file tree Collapse file tree 1 file changed +23
-2
lines changed Original file line number Diff line number Diff line change 2626 </ div >
2727
2828 < script >
29- // πππππππππππππππ
29+ const links = document . querySelectorAll ( 'a' ) ;
30+ const highlight = document . createElement ( 'span' ) ;
31+
32+ highlight . classList . add ( 'highlight' ) ;
33+ document . body . append ( highlight ) ;
34+
35+ function hilightLink ( ) {
36+ const linkBox = this . getBoundingClientRect ( ) ;
37+ const coords = {
38+ width : linkBox . width ,
39+ height : linkBox . height ,
40+ top : linkBox . top + window . scrollY ,
41+ left : linkBox . left + window . scrollX
42+ } ;
43+
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+
49+ links . forEach ( a => a . addEventListener ( 'mouseenter' , hilightLink ) ) ;
50+
51+
3052 </ script >
3153</ body >
3254</ html >
33-
You canβt perform that action at this time.
0 commit comments