11document . addEventListener ( 'DOMContentLoaded' , ( ) => {
2- const constrain = 200 ;
3- const mouseOverContainer = document . querySelector ( ".intro-text" ) ;
4- const ex1Layer = document . querySelector ( ".intro-heading" ) ;
5-
6- function transforms ( x , y , el ) {
7- const box = el . getBoundingClientRect ( ) ;
8- const calcX = - ( y - box . y - ( box . height / 2 ) ) / constrain ;
9- const calcY = ( x - box . x - ( box . width / 2 ) ) / constrain ;
10-
11- return "perspective(300px) "
12- + " rotateX(" + calcX + "deg) "
13- + " rotateY(" + calcY + "deg) " ;
14- } ;
15-
16- function transformElement ( el , xyEl ) {
17- el . style . transform = transforms . apply ( null , xyEl ) ;
2+ const constrain = 200 ;
3+ const mouseOverContainer = document . querySelector ( ".intro-text" ) ;
4+ const ex1Layer = document . querySelector ( ".intro-heading" ) ;
5+
6+ const contactSection = document . getElementById ( 'contact' ) ;
7+
8+ function transforms ( x , y , el ) {
9+ const box = el . getBoundingClientRect ( ) ;
10+ const calcX = - ( y - box . y - ( box . height / 2 ) ) / constrain ;
11+ const calcY = ( x - box . x - ( box . width / 2 ) ) / constrain ;
12+
13+ return "perspective(300px) "
14+ + " rotateX(" + calcX + "deg) "
15+ + " rotateY(" + calcY + "deg) " ;
16+ } ;
17+
18+ function transformElement ( el , xyEl ) {
19+ el . style . transform = transforms . apply ( null , xyEl ) ;
20+ }
21+
22+ mouseOverContainer . onmousemove = function ( e ) {
23+ const xy = [ e . clientX , e . clientY ] ;
24+ const position = xy . concat ( [ ex1Layer ] ) ;
25+
26+ window . requestAnimationFrame ( function ( ) {
27+ transformElement ( ex1Layer , position ) ;
28+ } ) ;
29+ } ;
30+
31+ if ( contactSection ) {
32+ const contactSectionObserverCallback = ( entries , observer ) => {
33+ entries . forEach ( ( entry ) => {
34+ if ( entry . isIntersecting ) {
35+ setTimeout ( ( ) => {
36+ document . querySelector ( 'input[name="name"]' ) ?. focus ( {
37+ focusVisible : true
38+ } ) ;
39+ } , 0 ) ;
40+ }
41+ } )
1842 }
19-
20- mouseOverContainer . onmousemove = function ( e ) {
21- const xy = [ e . clientX , e . clientY ] ;
22- const position = xy . concat ( [ ex1Layer ] ) ;
23-
24- window . requestAnimationFrame ( function ( ) {
25- transformElement ( ex1Layer , position ) ;
26- } ) ;
27- } ;
43+
44+ const contactSectionObserver = new IntersectionObserver ( contactSectionObserverCallback ) ;
45+
46+ contactSectionObserver . observe ( contactSection ) ;
47+ }
48+
49+ document . querySelectorAll ( '.input-group-addon' ) . forEach ( el => el . addEventListener ( 'click' , ( { currentTarget } ) => { currentTarget ?. parentNode . querySelector ( 'input' ) ?. focus ( ) } ) )
2850} )
0 commit comments