Troubleshooting: GSAP Scrolltrigger malfunctions when using multiple triggers

Having multiple triggers with different functionalities:

  1. Show or remove a canvas
  2. Change the background color of a section
  3. Play or pause video when in view
  4. Play or pause CSS animation

The first two triggers work fine individually, but I am encountering an error with the play/pause video trigger: Uncaught TypeError: Cannot read properties of null (reading 'play'). I have followed the GSAP tutorial, so I suspect there might be a conflict with the previous triggers.

  const hideWebGl = gsap.timeline({
  scrollTrigger: {
    trigger: ".wriggle-cursor",
    scrub: true,
    start: 'top 100%',
    end: 'top -125%',
      onEnter: () => $('.home #canvas').css('display','block'),
      onLeave: () => $('.home #canvas').css('display','none'),
      onEnterBack: () => $('.home #canvas').css('display','block'),
      onLeaveBack: () => $('.home #canvas').css('display','none'),
  },
});

const projectsBackground = gsap.timeline({
  scrollTrigger: {
    trigger: ".projects-section-next .whatwedo",
    scrub: true,
    start: 'top 60%',
    end: 'top -300%',
      onEnter: () => $('.projects-section-next .whatwedo').css('background-color','white'),
      onLeave: () => $('.projects-section-next .whatwedo').css('background-color','transparent'),
      onEnterBack: () => $('.projects-section-next .whatwedo').css('background-color','white'),
      onLeaveBack: () => $('.projects-section-next .whatwedo').css('background-color','transparent'),
  },
});

let allVideoDivs = gsap.utils.toArray('.vid-gsap');

allVideoDivs.forEach((videoDiv, i) => {
  
  let videoElem = videoDiv.querySelector('video')
  
  ScrollTrigger.create({
    trigger: videoElem,
    start: 'top 80%',
    end: 'top 20%',
    markers: true,
    onEnter: () => videoElem.play(),
    onEnterBack: () => videoElem.play(),
    onLeave: () => videoElem.pause(),
    onLeaveBack: () => videoElem.pause(),
  });
  
});

let allCssAnimation = gsap.utils.toArray('.ticker-marquee');

allCssAnimation.forEach((cssAnimation, i) => {
  
  let cssElem = cssAnimation.querySelector('video')
  
  ScrollTrigger.create({
    trigger:cssElem,
    start: 'top 80%',
    end: 'top 20%',
    markers: true,
    onEnter: () => cssElem.css('-webkit-animation-play-state','running'),
    onLeave: () => cssElem.css('-webkit-animation-play-state','paused'),
    onEnterBack: () => cssElem.css('-webkit-animation-play-state','running'),
    onLeaveBack: () => cssElem.css('-webkit-animation-play-state','paused'),
  });
  
});

Answer №1

After making this adjustment to the video play and pause feature, everything worked perfectly.

const allVids = gsap.utils.toArray('video')

allVids.forEach(function(vid, num) {
    
  ScrollTrigger.create({
    trigger: vid,
    start: 'top center',
    end: 'bottom center',
    onEnter: () => vid.play(),
    onEnterBack: () => vid.play(),
    onLeave: () => vid.pause(),
    onLeaveBack: () => vid.pause(),
  });
})

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: Unable to execute map() function on commands.options? while configuring slash commands

discord js v13.3.1 I have configured my bot to update and deploy slash commands using a specific command called "deploy". The structure of the deploy command is as follows: module.exports = { name: "deploy", description: "deploys sl ...

"ExceptionThrownByMoveTargetOutOfBounds in Selenium WebDriver for IE9 and Firefox

Having trouble with the FireFox/IE9 driver in Selenium? When using the Actions class and its moveToElement method, I keep encountering a MoveTargetOutOfBoundsException error. Despite trying different solutions like Coordinates, Point, and javascriptexecuto ...

How can we ensure that an enum is accessible throughout the entire meanjs stack?

Currently, I am exploring the meanjs technology stack and facing a challenge in creating a centralized enum array that can be accessed throughout the project, from MongoDB to Angular. Can anyone suggest a smart solution for accomplishing this task? ...

Resolve the issue pertaining to the x-axis in D3 JS and enhance the y-axis and x-axis by implementing dashed lines

Can anyone assist with implementing the following features in D3 JS? I need to fix the x-axis position so that it doesn't scroll. The values on the x-axis are currently displayed as numbers (-2.5, -2.0, etc.), but I want them to be shown as percentag ...

Employing buttons and state to eliminate an item from a roster

My list is generated using the following code: return (this.state.limit).fill().map((_,index) => { return ( <div key={`${index}`}> Item </div> ) ) I'm wondering how I can implement a button that allows me to remove a specific ...

The Bootstrap datepicker functions properly when used in plain HTML, but encounters issues when implemented within the .html()

Using HTML: <input class="m-ctrl-medium date-picker" size="16" type="text" id='lateETD1' name="dateRecv" value=""/> Not working with script: var ETD = $("#ETD"); ETD.html("<input class='m-ctrl-medium date-picker' id='la ...

Verify Ionic storage for an item

Is there a way to display an introductory slider only once for new users when they install the app? Solution If the user installs the app, set an item in the storage called intro with a value of false When the user opens the app, check the intro item. I ...

Angular 7's URL updates, but no other actions take place

I am new to posting here and feeling quite desperate. Currently, I am working with Angular 7 and facing an issue. The problem arises when I manually enter the desired URL, everything works perfectly. However, when I use RouterLink by clicking a button, the ...

Issue with async waterfall not triggering the next callback function when combined with a promise

async.waterfall(eventIDs.map(function (eventId) { console.log(eventId); return function (lastItemResult, nextCallback) { if (!nextCallback) { nextCallback = lastItemResult; las ...

Issues with HTML keycodes not functioning properly in Firefox

Here is the code I am using: function restrictInput(e) { var charCode = (e.which) ? e.which : ((e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : 0)); if((charCode < 48 || charCode > 57) && ( ...

Utilize an npm package to transform a CSS file into inline styles within an HTML document

I have an HTML file with an external CSS file and I would like to inline the styles from the external style sheet into one inline <style> tag at the top of the head. Any assistance would be greatly appreciated. Note: I do not want to use the style a ...

Having trouble setting up npm package (fsevents) on Mac OS Catalina?

I'm facing an error when trying to run the npm install express --save command. Can someone assist me in resolving this issue? The error message is as follows: > email@example.com install /Users/delowar/Desktop/ytdl/node_modules/chokidar/node_modu ...

Implement two different styles within an element's style properties

Welcome everyone, I have a question regarding adding marquee effects to a table row along with highlighting it. Is it possible to include moving text from left to right in the same active row? For example, let's say that the current time is 12:45 AM. ...

"Emphasizing the Html.ActionLink menu for improved user navigation and

Currently, I am facing an issue with my menu. I want to clear previously visited links while keeping the current one styled as a:visited in CSS. Although I have attempted to achieve this, unfortunately, the code is not functioning properly. Here is what I ...

typescript: Imported modules in typescript are not functioning

I'm facing an issue where I installed the 'web-request' module but unable to get it working properly. Here is my code: npm install web-request After installation, I imported and used it in my class: import * as WebRequest from 'web-r ...

Unable to submit form in Nextjs using react-bootstrap

Instructions To create a registration form, follow these steps: Fill out the form on the register page and then click submit. The react-bootstrap button will trigger the handleSubmit() function using onSubmit={}. Expected vs Actual Outcome I attempted va ...

Switching between languages dynamically with Angular JS using $translateProvider and JSON files

I currently have a collection consisting of 6 different JSON files. en.json es.json fr.json it.json ja.json zh.json An illustration of the data present in each file is as follows (in this instance, considering en.json): { "SomeText": "Test in Englis ...

What is the best way to retrieve information in Next.js when there are changes made to the data, whether it be new

Could you share a solution for fetching data in Next.js when data is added, deleted, or edited? I tried using useEffect with state to trigger the function but it only works when data is added. It doesn't work for edit or delete operations. I have mult ...

What are the implications of using eval() to interpret function parameters?

I've recently utilized Hopscotch to create a interactive tour on my Website. To implement this, you need to create a JavaScript object as a parameter to trigger the startTour() function which will kick off the tour. For instance, in this case, the tou ...

"Encountering an error in Vue3 CompositionAPI: 'quizz is not defined' while trying to call a function from the

When attempting to call a function, I am encountering an error that says "Uncaught ReferenceError: quizz is not defined." <script setup> import { defineProps } from "vue"; import { useRouter } from "vue-router"; const router = us ...