Giter VIP home page Giter VIP logo

react-scroll-horizontal's Introduction

React Scroll Horizontal

Scroll horizontally with the mousewheel!

NPM

demo

npm install --save react-scroll-horizontal

How it Works

Feed <HorizontalScroll> one child, or many children. So long as they have a static width, this component will take care of the rest. Note: the width of the children must be greater than the width of the <HorizontalScroll>


Usage

npm i react-scroll-horizontal
  <HorizontalScroll
    pageLock      = { bool }
    reverseScroll = { bool }
    style         = { object }
    config        = {{ stiffness: int, damping: int }}
    className     = { string }
    animValues    = { int }
    >
     { children }
  </HorizontalScroll>

Props

  • pageLock - Adds a lock__ class to the HTML body
  • reverseScroll - Reverses the scroll direction
  • style - Pass a style object through to parent div
  • config - Passes a spring config object to React Motion
  • className - Classnames to pass into the component
  • animValues - Emulate scroll by passing a delta value

Gotchas

  • Child item(s) must be px/em/vw - no percentages (yet)
  • Flexbox weirdness in IE

Arbitrary Parent/Child Widths Example

import React, { Component } from 'react'
import HorizontalScroll from 'react-scroll-horizontal'

class ScrollingHorizontally extends Component {
  render() {
    const child   = { width: `30em`, height: `100%`}
    const parent  = { width: `60em`, height: `100%`}
    return (
      <div style={parent}>
        <HorizontalScroll>
            <div style={child} />
            <div style={child} />
            <div style={child} />
        </HorizontalScroll>
      </div>
    )
  }
}

Full Width Example

import React, { Component } from 'react'
import HorizontalScroll from 'react-scroll-horizontal'

class ScrollingHorizontally extends Component {
  render() {
    const child = { width: `300em`, height: `100%`}
    return (
      <body>
        <HorizontalScroll>
          <div style={child} />
        </HorizontalScroll>
      </body>

    )
  }
}

Roadmap

  • Normalize mouse delta values (see: #1)
  • Implement tests ✨
  • Perf optimizations
  • Ability to swap out animation engines (maybe)

Contributing

Want to help out? Great!

Sites/Apps using React Scroll Horizontal

ieaseMusic


MIT © hew

react-scroll-horizontal's People

Contributors

dimkabelkov avatar emmaramirez avatar felix-digitalkarma avatar gretzky avatar hew avatar januarsmad avatar josephdburdick avatar kimborgen avatar melmepham avatar nadelalon avatar trazyn avatar whizsid avatar zachgibson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-scroll-horizontal's Issues

Maximum call stack exceeded

When I have only 3 slides or less - I get the below error when I try to scroll. Any idea why this is coming?

Uncaught RangeError: Maximum call stack size exceeded

Add Null Checks for Elements

I just started using this library so I don't have much info to give, but it's maybe worth adding some null check for el there if you can't find it in the DOM.

TypeError: Cannot read property 'lastElementChild' of null
  at apply(./node_modules/react-scroll-horizontal/dist/index.es.js:1738:1)
  at n(./node_modules/@sentry/browser/dist/index.js:3114:1)

image

Scrollbar

Hello, I wanted to make a styled scrollbar with this component, but when I actually style it and make it visible in the files of the component, it has pretty strange behavior. The scrollbar becomes bigger when I scroll the list with my mouse wheel instead of moving with the list. Do you know what might cause such problem?

Mouse Deltas not Normalized by React

I have encountered a situation where certain mice have vastly different mouse deltas on Firefox as compared with the rest of the browsers. Like, 10x difference.

This shouldn't happen, as in theory React's onWheel() should be normalizing all the deltas across browsers. That is what React advertises it does, but it seems that it is unable to handle certain edge cases.

Expose interpolatedStyle

My use-case needs to animate more than just translation. It’d be great to have interpolatedStyle exposed to children of HorizontalScroll . I’d be happy to implement this if you’re down.

Not mobile responsive

So I have used this scroll, for a website I am making (checkout aplaceofdreams.herokuapp.com) - but its not mobile responsive, I am interested in learning how to do this, and adding to this module to make it a feature, would anyone have any ideas on where to start looking?

Roadmap to 2.0

Main things I'd love to see in version 2.0

Normalize mouse delta values (see: #1) — not sure this is still an issue with React 16.
Implement tests ✨
Perf optimizations  
Ability to swap out animation engines (maybe)

Component starts already scrolled

I'm building an eCommerce site with React and for the product page I'm using this package for the images.

Each product has different colours, so when you change the colour the page stays the same but the information changes.

Imagine you start by seeing a product with 3 images and scroll to the end and then you click on a colour with only one image. This will be what you see:
Screenshot 2022-07-13 at 11 54 57

It's like it's looking for a picture which is not there plus you have no scrolling ability.

Is there any way to like 'reinitialise' it?

Thanks

Provide a button for manual scrolling

I'm trying to trigger a WheelEvent for manual scrolling with a button.
Have you thought in providing some manual button for scrolling? I have some users that don't naturally scroll and are expecting a button to move around.

Tranks!

Add react-draggable?

Hi!

First off, loving your project.

As mobile support is a must these days it is sad that this project does not support it. I would like to have one component for one "feature" if you know what i mean.

I've been able to include react-draggable and react-scroll-horizontal in my own project. And it seems to work pretty good! But it was not as easy as I would like.

Is integrating react-draggable in this project a feature you would like? @hew
And something that I should try solving?

Alternativly we can just add a detailed entry in the readme on how to integrate the two projects.

Previous work

I saw that in #4 you allready tried this approch, any luck there? @zachgibson seems to have made progress on this (#4 & #28), but has not submitted a PR.

General Approch:

  1. When dragging you get a delta x from draggable. (But no dragging / moving is happening because we disable that)
  2. This delta x is passed down to the HorizontalScroll component on the new prop animValues (See PR #36 )
  3. The horizontal scroll component then does it's thing as if a scroll had just happend by updating the state variable animValues with the new prop and then calculating new motion.
  4. Profit.

Reaching the end of the horizontal scroll container

Hi there

I'd just like to find out if there is a way to tell when you've reached the end of the horizontal scroll container?
I saw the PR which has not yet been merged in, so just wanted to find out if there is a work around that I could use for now?

Thanks!

ERR! Could not resolve dependency: peer react@"^15.0.0 || ^16.0.0"

Hello there,

I tried to install react-scroll-horizontall plugin but it failed because of react core dependencies. Please, read error below.

Is there an easy way to update dependencies?

Failed to compile.

Module not found: Error: Can't resolve 'react-scroll-horizontal' in '/src/components'
ERROR in ./src/components/Currencies.js 5:0-55
Module not found: Error: Can't resolve 'react-scroll-horizontal' in '/src/components'

webpack compiled with 1 error
^X^C
$ npm install --save react-scroll-horizontal
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! react@"^18.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.0.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/react-scroll-horizontal
npm ERR! react-scroll-horizontal@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR! /.npm/_logs/2022-10-22T20_29_03_166Z-debug-0.log

Doesn't support percentages

I know this is in the documentation but we know the reason it doesn't work with percentages maybe a plan of action to support it?

It would be a handy feature.

Crazy "shiver" behaviour when zoomed out

https://imgur.com/a/RzCHH

In the GIF its less visible but the shivering is actually much faster then it looks. Whenever Im zoomed out and the content is in the center of the scroll area I am NOT scrolling with my mouse. The back and forth behaviour came from nothing.

EDIT: if it means anything, I had to remove react v15 from the node modules folder of the "react-scroll-horizontal" module because I got the "You may have multiple copies of React loaded" error before. After removing react and react-dom it worked fine.

I have react v16 installed

Prevent when scrolling child component

Within the full page horizontal scroll, I have another component with vertical scroll. Is there a way to prevent the horizontal scroll from triggering when scrolling in the child component?

Cannot resolve 'react-motion'

Hi, great plugin! I was recreating something just like this from scratch and stumbled upon this. I'm interested in leveraging this but it I've come across the following error:

ERROR in ./~/react-scroll-horizontal/dist/react-scroll-horizontal.js
Module not found: Error: Cannot resolve module 'react-motion' in /Users/jb/Sites/Joey/node_modules/react-scroll-horizontal/dist
 @ ./~/react-scroll-horizontal/dist/react-scroll-horizontal.js 19:19-42

I've looked into your package.json and it appears you've left wildcards * for version numbers of some your dependencies. This will request the latest and greatest but it opens your plugin to the possibility of breaking changes.

Not able to active the pageLock= {bool}

Hey, thanks for this great package!

Here's my code:

     horizontalPageDesktop = () => {
       if(this.props.isSeeAll){
         return null;
       }else{
         if(this.state.renderProjectInfo){
           return (
             <div>
               <div id="container">
                 {this.renderProjectMedia()}
               </div>
           </div>
           )
         }else{
           return (
               <div>
                 <div
                   id="container_2">
                   {this.renderButtonCloseInfo()}
                   <HorizontalScroll
                     pageLock={true}
                     className = { "horizontal_scroll" }
                     reverseScroll = {true}>
                     {this.renderProjectMedia()}
                    </HorizontalScroll>
                 </div>
             </div>
           )
         }
       }
    }

When I implement the pageLock, I see the the body is locked__ . However I I'm not able to fully lock your component with css nor JavaScript. I filled a StackOverflow issue here with my attempts. What do you suggest so that I can avoid the transform: translate3d(); to occur?

Grey background when adding the scroll around my components

Hi, I keep getting just a grey screen when trying to work this. It won't scroll vertically (as it did before adding the scroll) nor horizontally. I've made sure I have enough projects to notice the scroll as one wouldn't make a difference. Please find code snippet below:

screenshot 2018-11-07 at 22 46 17

Any ideas?

Its not working for me

Code :

`import React, { Component } from 'react';
import HorizontalScroll from 'react-scroll-horizontal'

class Scroll extends Component {
render() {
return (



<div style={{width : '300px',height : '300px'}} />


);
}

}

export default Scroll;`

TypeError: _this4.props.children is not a function.

React version 16. please let me know what is the exact issue ?

Question

Hello how are you? Well, I have a question. I would like to start my Scroll on a child who has an active class. Is it possible to do that?

question - What am I doing wrong to not get to use this awesome component?

###yarned all dependencies, followed readme exact and when I spin it up I get this error:

####TypeError: _this4.props.children is not a function

react-scroll-horizontal.js:212 Uncaught TypeError: _this4.props.children is not a function
at Object.children (react-scroll-horizontal.js:212)
at Motion.render (Motion.js:255)
at finishClassComponent (react-dom.development.js:13193)
at updateClassComponent (react-dom.development.js:13155)
at beginWork (react-dom.development.js:13824)
at performUnitOfWork (react-dom.development.js:15863)
at workLoop (react-dom.development.js:15902)
at renderRoot (react-dom.development.js:15942)
at performWorkOnRoot (react-dom.development.js:16560)
at performWork (react-dom.development.js:16482)
at performSyncWork (react-dom.development.js:16454)
at requestWork (react-dom.development.js:16354)
at scheduleWork$1 (react-dom.development.js:16218)
at scheduleRootUpdate (react-dom.development.js:16785)
at updateContainerAtExpirationTime (react-dom.development.js:16812)
at updateContainer (react-dom.development.js:16839)
at ReactRoot../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.development.js:17122)
at react-dom.development.js:17262
at unbatchedUpdates (react-dom.development.js:16679)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:17258)
at Object.render (react-dom.development.js:17317)
at Object../src/index.js (index.js:8)
at webpack_require (bootstrap ee20e96b393a3ea4c35e:678)
at fn (bootstrap ee20e96b393a3ea4c35e:88)
at Object.0 (app.css?23b1:26)
at webpack_require (bootstrap ee20e96b393a3ea4c35e:678)
at ./node_modules/ansi-regex/index.js.module.exports (bootstrap ee20e96b393a3ea4c35e:724)
at bootstrap ee20e96b393a3ea4c35e:724

Looking for a Maintainer 👀

I'm currently looking for a maintainer for this project. It needs a lot of love, and I'm currently too busy with work to really dedicate any time to a re-write.

If anyone reading this is interested, let me know.

Scroll to child element?

Hi,

Is there a way I can use the AnimValues to scroll to a child element within the <HorizontalScroll /> elements? Currently using anchor tags breaks the scroll entirely.

Appreciate all the help I can get! :)

Question: How to Handle Responsive

Hey, so I am using this, and I am wondering how I can make it responsive, I know that the width and height have to be defined, so does that mean responsiveness isn't really a thing without a heap of media queries?

Can't resolve 'react-motion'

First attempt to import and use HorizontalScroll resulted in this error:

Module not found: Error: Can't resolve 'react-motion' in '...\node_modules\react-scroll-horizontal\dist'

Installing react-motion via npm fixed the problem. Is this a dependency that should be included?

Trying to install with react v17

Its not letting me install because of different react versions. Has anyone tried yet? Or should I just run

npm i react-scroll-horizontal --force

and hope nothing breaks?

MOBILE not working.

Does anyone have any idea how I can disable this element if they are using a mobile device?
<HorizontalScroll reverseScroll = { Boolean }>
I tried a bunch of things but have no idea.

Thanks!

linked demo doesn't work

Hey

so I came across this plugin seaching for an horinzontal solution, opened the demo and it didn't scroll, either with the mosewheel nor while dragging

Scroll event listener doesn’t work for horizontal

Event listener for window doesn’t trigger on ‘scroll’ when scrolling horizontal. And the documentation doesn’t explain how animValues work. So what would be the solution here, trying to animate my background when in a certain part of my site.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.