jQuery plugin for horizontally scrolling galleries

Overview

jQuery Horiztonal Scroll Gallery

This jQuery plugin slides through a horiztonal gallery of items as you scroll down. It makes use of position:sticky so that the gallery briefly fixes in place as it scrolls horizontally See example here (scroll down the page)

Ready to download? Get the minified JS file here: https://github.com/jrue/jquery-horizontal-scroll/blob/main/dist/jquery-horizontal-scroll.min.js

Usage:

The gallery needs to be an HTML element with some child elements one-level down. It will take those first-level children, and automatically adjust them into a filmstrip element with all of the correct CSS, so there is little to do other than add the HTML. The child elements can be images, or div tags, or whatever. The film strip's height will be based on the tallest element it finds.

Example HTML:

<div class="horizontal-scroll">
  <div class="example">
    <img src="images/desk-1.jpg" class="img-fluid" alt="desk">
  </div>
  <div class="example">
    <img src="images/desk-2.jpg" class="img-fluid" alt="desk">
  </div>
  <div class="example">
    <img src="images/desk-3.jpg" class="img-fluid" alt="desk">
  </div>
  <div class="example">
    <img src="images/desk-4.jpg" class="img-fluid" alt="desk">
  </div>
</div>

This plugin requires jQuery (tested with 3x, but should work on earlier versions) and will need to be loaded after the jQuery library.

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="jquery-horizontal-scroll.min.js"></script>

Target the CSS class of your containing element and run the horizontalScroll() method. (In the following example it's .horizontal-scroll) and set the options you want. The main option is how tall you want the containing element. The shorter it is, the more quickly it will scroll through the gallery. It defaults to 300vh which is 300 percent of the viewport height. You can try different numbers to see how it affects the scroll.

Larger numbers require more scroll effort to slide the gallery, and thus results in a slower scrolling gallery.

$( '.horizontal-scroll' ).horizontalScroll({
  containerHeight: "300vh"
});

Additional Options

You shouldn't need to add these additional options. In most cases they're auto detected. But I put them here just in case someone wanted to override the defaults.

  • containerHeight - The height of the container, which requires more scrolling.
  • itemsHeight - Automatically based on the tallest item it finds, but you can set it yourself. An overflow hidden property will chop off anything protruding if you set it smaller than an element.
  • width - Width of the strip of items. Automatically based on number of items multipled by the width of the main container. You can override here.
  • paddingTop - Auto detects if you had padding on the container. But this will affect the point in which the stickiness catches.
  • paddingLeft - Auto detects, but if you had padding-left on the container, it will ensure it carries over from the starting location of the film strip.

MIT License

You might also like...

pagePiling plugin by Alvaro Trigo. Create a scrolling pile of sections. http://alvarotrigo.com/pagePiling/

pagePiling plugin by Alvaro Trigo. Create a scrolling pile of sections. http://alvarotrigo.com/pagePiling/

pagePiling.js Pile your sections one over another and access them scrolling or by URL! Live demo Creating hugeinc.com website with pagePiling.js Who i

Dec 29, 2022

Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mouse is over the marquee, and all with vanilla JavaScript.

TEG Marquee Make the content slide prettily across the screen with variable sizes of scrolling items, in any of four directions, pausing while the mou

Dec 30, 2021

Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra performance.

parallax-vanilla.js Seamless and lightweight parallax scrolling library implemented in pure JavaScript utilizing Hardware acceleration for extra perfo

Dec 16, 2022

Dynamic web app 'presentations', driven by user scrolling, inspired by the NYT

Museé A small Typescript-based web app, inspired by the NYT Close Reading of Auden's Museé des Beaux Arts. Introduction I loved the NYT Close Reading

Mar 13, 2022

Given a list of items, only render what's visible on the screen while allowing scrolling the whole list.

Solid Windowed Given a list of items, only render what's visible on the screen while allowing scrolling the whole list. A Solid component. See https:/

Dec 21, 2022

A lightweight, performant, and simple-to-use wrapper component to stick section headers to the top when scrolling brings them to top

A lightweight, performant, and simple-to-use wrapper component to stick section headers to the top when scrolling brings them to top

Jun 27, 2022

Scrolling navigation component for web apps

Slinky.js Create beautiful scrolling driven navigation lists with stacking headers that remain visible at all times. Scroll around on the plugin homep

Nov 16, 2022

A lightweight script to animate scrolling to anchor links.

DEPRECATION NOTICE: Smooth Scroll is, without a doubt, my most popular and widely used plugin. But in the time since I created it, a CSS-only method f

Dec 26, 2022

A simple smooth scrolling using 100% vanilla JavaScript.

SmoothScroll.js A simple smooth scrolling using 100% vanilla JavaScript, and it's only 3kb! Demo Usage // index.html html head link rel="

Aug 24, 2022
Comments
  • Multiple instances

    Multiple instances

    Had a small issue where the scroller didn't seem to work when multiple instances were used on the same page

    The strip-holder element was animating on all scrollers at the same time

    Managed to fix this with the following (commented lines are the original):

      if(currScrollTop < startOfScroll){
          $(el).find('.strip-holder').css("transform", "translate3d(0px,0px,0px)");
          // $(".strip-holder").css("transform", "translate3d(0px,0px,0px)");
      }
      
      if(currScrollTop > startOfScroll && currScrollTop < endOfScroll){
          $(el).find('.strip-holder').css("transform", `translate3d(-${percentScrolled * stripHolderWidth}px,0px,0px)`);
          // $(".strip-holder").css("transform", `translate3d(-${percentScrolled * stripHolderWidth}px,0px,0px)`);
      }
      
      if(currScrollTop > endOfScroll){
          $(el).find('.strip-holder').css("transform", `translate3d(-${stripHolderWidth}px,0px,0px)`);
          // $(".strip-holder").css("transform", `translate3d(-${stripHolderWidth}px,0px,0px)`);
      }
    
    opened by thomEpps 0
  • Active Class

    Active Class

    This plugin probably saved me hours so thanks a lot!

    The only thing I needed to add was a little snippet to set an active class on the slide that was in the viewport. Someone else might find it useful so will stick it here 👍

      $(window).scroll(function() {
    	  $(".scrollingContainerClass").each(function(){
    		  var panelPositionLeft = $(this).offset().left;
    		  if (panelPositionLeft <= 0 ) {
    			  $(this).addClass("activeClass");
    		  } else {
    			  $(this).removeClass("activeClass")
    		  }
    	  });
      });
    
    opened by thomEpps 0
Owner
Jeremy Rue
Jeremy Rue
A Simple yet extendable jQuery modal script built for use with inline HTML, images, videos, and galleries.

jQuery Chaos Modal A Simple yet extendable jQuery modal script built for use with inline HTML, forms, and images in mind. There are many other modal p

Matthew Sigley 3 Oct 8, 2020
Next-gen mobile first analytics server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js, headless, API-only, horizontally scaleable.

Introduction to Awacs Next-gen behavior analysis server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js

Socketkit 52 Dec 19, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Horizontally scalable blockchain using STARK's and partitioned transactional memory

quark quark - quick STARK! A decentralized horizontally-scaled state machine that can transfer 1,000,000 unique tokens on Uniswap in a single atomic t

Liam Zebedee 56 Nov 25, 2022
An infinite scrolling plugin for jQuery.

jScroll - jQuery Plugin for Infinite Scrolling / Auto-Paging Official site at jscroll.com. Copyright © Philip Klauzinski Dual licensed under the MIT a

Philip Klauzinski 1.1k Dec 29, 2022
Parallax scrolling jQuery plugin

paroller.js A lightweight jQuery plugin that enables parallax scrolling effect You can use it on elements with background property or on any other ele

null 579 Dec 26, 2022
jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested on Firefox/Chrome/Maxthon/iPhone/Android. Very light <7ko min.js and <1Ko min.css.

Nice-Scrollbar Responsive jQuery based scrolling Bar, for PC and Smartphones (touch events). It is modern slim, easy to integrate, easy to use. Tested

Renan LAVAREC 2 Jan 18, 2022
Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed.

scrooth Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed. Why? I needed that, and I was unable to find p

Rafał Spiżewski 20 Aug 29, 2022