1+ import React from "react" ;
2+ import Card from "react-bootstrap/Card" ;
3+ import { useEffect } from "react" ;
4+ import { useMediaQuery } from "react-responsive" ;
5+
6+ function ScrollTrigger ( ) {
7+
8+ const isTablet = useMediaQuery ( { minWidth : 768 , maxWidth : 1368 } ) ;
9+ const isDesktop = useMediaQuery ( { minWidth : 1081 } ) ;
10+ const isDevelopment = process . env . NODE_ENV === "development" ;
11+
12+ useEffect ( ( ) => {
13+ let currentIntersectedElement = null ;
14+ const observer = new IntersectionObserver ( ( entries ) => {
15+ entries . forEach ( ( entry ) => {
16+ if ( entry . isIntersecting ) {
17+ // Reset previous element
18+ // if (currentIntersectedElement && currentIntersectedElement !== entry.target) {
19+ // currentIntersectedElement.style.opacity = 0.1;
20+ // }
21+ entry . target . style . opacity = 1 ;
22+ currentIntersectedElement = entry . target ;
23+ } else {
24+ entry . target . style . opacity = 0.1 ;
25+ if ( currentIntersectedElement === entry . target ) {
26+ currentIntersectedElement = null ;
27+ }
28+ }
29+ } ) ;
30+ } , {
31+ // desktop and laptops options
32+ // threshold: 1,
33+ // rootMargin: "-150px",
34+ // Tablets options
35+ // threshold: 0.7,
36+ // rootMargin: "-50px",
37+ threshold : isTablet ? 0.5 : 1 ,
38+ rootMargin : isTablet ? "-200px" : "-150px" ,
39+ } ) ;
40+
41+ if ( isDevelopment ) { console . log ( observer . thresholds , observer . rootMargin ) }
42+ console . log ( observer . thresholds , observer . rootMargin ) ;
43+ console . log ( window . innerWidth , window . innerHeight ) ;
44+
45+
46+ document . querySelectorAll ( '.triggerSpan' ) . forEach ( ( element ) => {
47+ element . style . opacity = 0.1 ;
48+ observer . observe ( element ) ;
49+ } ) ;
50+
51+ return ( ) => observer . disconnect ( ) ;
52+ } , [ isTablet , isDesktop , isDevelopment ] ) ;
53+
54+ return (
55+ < Card className = "quote-card-view" >
56+ < Card . Body >
57+ < div id = "aboutMe" className = "body" >
58+ < div className = "triggerDiv" tg-name = "_" tg-ref = "container" tg-from = "1" tg-to = "8" tg-step = "1" >
59+ < section tg-name = "_" tg-map = "1,2,3,4,5,6,7,8,9,10: 1" >
60+ < span className = "triggerSpan" tg-name = "opacity" tg-filter = "2!" tg-follow = "container" >
61+ A University Of Newcastle Student Led Design Studio.
62+ </ span >
63+ < br />
64+ < span className = "triggerSpan" tg-name = "opacity" tg-filter = "3!" tg-follow = "container" >
65+ We work together with communities, governments, universities and select start-up businesses
66+ </ span > < br />
67+ < span className = "triggerSpan" tg-name = "opacity" tg-filter = "4!" tg-follow = "container" >
68+ We work on large scale projects from illustration and graphic design through to campaigns and creative consultancy.
69+ </ span >
70+ < br />
71+ < span className = "triggerSpan" tg-name = "opacity" tg-filter = "5!" tg-follow = "container" >
72+ Feel free to get in touch for an obligation free consultation. And everything from Aye! to Zed!
73+ </ span >
74+ </ section >
75+ </ div >
76+ </ div >
77+ </ Card . Body >
78+ </ Card >
79+ ) ;
80+ }
81+
82+ export default ScrollTrigger ;
0 commit comments