The place for more technical questions for those who want to create new pagetypes or bespoke functionality.

Smooth scrolling on Bootstrap pages

  • Neil Pollock
  • Auteur du sujet
  • Hors Ligne
  • Membre premium
  • Membre premium
Plus d'informations
il y a 8 ans 6 mois #4897 par Neil Pollock
Smooth scrolling on Bootstrap pages a été créé par Neil Pollock
I'm trying to add some smooth srolling to Bootstrap pages (so that clicking the in-page links in the left-hand menu will cause the page to scroll rather than jump to the specific section).

I'm using some jQuery which selects all hashed links and then applies the scroll animation when clicked. It mostly works, except that it breaks the functionality of any carousel image viewers on the page (since they also use hashed links).

Just wondering if there was an easy way around this, other than manually excluding any carousels, e.g.:
Code:
$("a[href^='#']").not('[href="#car0_6"]').not('[href="#car5_1"]').not('[href="#car6_4"]').click(function () ...etc

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 8 ans 6 mois #4900 par Fay
Réponse de Fay sur le sujet Smooth scrolling on Bootstrap pages
Hi Neil

The carousels are in a div with the class 'carousel' so you could probably use this parent class for the exclusion instead of looking at every single link inside it.

e.g. something along the lines of...
Code:
$("a[href^='#']").not('.carousel a').click(function ()...)

Or make sure you're only selecting those in the left menu to begin with:
Code:
$("#contentTable a[href^='#']").click(function ()...)

I haven't tried these out but something along these lines should work
Les utilisateur(s) suivant ont remercié: Neil Pollock

Connexion ou Créer un compte pour participer à la conversation.

  • Neil Pollock
  • Auteur du sujet
  • Hors Ligne
  • Membre premium
  • Membre premium
Plus d'informations
il y a 8 ans 6 mois #4911 par Neil Pollock
Réponse de Neil Pollock sur le sujet Smooth scrolling on Bootstrap pages
Thanks, that's just what I was looking for.

And so simple! I was clearly overthinking the problem...

Connexion ou Créer un compte pour participer à la conversation.

Modérateurs: JohnSmith
Temps de génération de la page : 0.386 secondes
Copyright © 2026 The Xerte Project.
Xerte logo Apereo logo OSI Logo