Jump to content
Search Community

scroll smoother + bootstrap modal

Cyrille Brotto test
Moderator Tag

Go to solution Solved by Cyrille Brotto,

Recommended Posts

hello,
I use webpack+gsap+scrollsmoother+bottstrap. Here is my problem :

 

import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger.js";
import { ScrollSmoother } from 'gsap/ScrollSmoother.js';
import { ScrollToPlugin } from 'gsap/ScrollToPlugin.js';

gsap.registerPlugin(ScrollTrigger, ScrollSmoother);


// import 'bootstrap/dist/js/bootstrap.bundle.min.js';
import Bootstrap from 'bootstrap/dist/js/bootstrap.bundle.min.js'

const myModal = new bootstrap.Modal(document.getElementById('myModal'), {
  keyboard: false,
  backdrop: 'static'
});

let smoother = ScrollSmoother.create({
  wrapper: '#smooth-wrapper',
  content: '#smooth-content',
  smooth: 2,
  smoothTouch: 0.5,
  effects: true,

with this JS, I have a bootstrap modal in my html code which opens but scroll smoother no longer works. When I comment out the "const modal" variable, scroll smoother works but the modal does not open !!!

 

what is missing to make the two work together?

Thank you for your answers

Link to comment
Share on other sites

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

Please don't include your whole project. Just some colored <div> elements and the GSAP code is best. See if you can recreate the issue with as few dependencies as possible. Start minimal and then incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, at least we have a reduced test case which greatly increases your chances of getting a relevant answer.

 

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

Finally you could try ScrollSmoother's paused method:

https://gsap.com/docs/v3/Plugins/ScrollSmoother/paused()

 

Also it has been reported in the forums that Bootstrap adds scroll-behavior: smooth globally, which interferes with ScrollSmoother, so you might want to add some CSS that overrides that globally.

 

Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

  • Solution

Hello,
I solved my problem opening modal. I didn't know that it had to be positioned outside of the scroll smoother tags.

 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <title>GSAP et Bootstrap</title>
</head>
<body>

  <div id="smooth-wrapper">
    <div id="smooth-content">
      <!-- Votre contenu ici -->
    </div>
  </div>

  <!-- Modal -->
  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="myModalLabel">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
          Modal body text goes here.
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
          <button type="button" class="btn btn-primary">Save changes</button>
        </div>
      </div>
    </div>
  </div>

  <script src="bundle.js"></script> <!-- Votre fichier JS compilé -->
</body>
</html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...