GithubHelp home page GithubHelp logo

markcellus / scroll-js Goto Github PK

View Code? Open in Web Editor NEW
230.0 230.0 32.0 5.85 MB

Light cross-browser scroller that uses native javascript

License: MIT License

JavaScript 23.59% TypeScript 76.41%
animation cross-browser ember es6 javascript polymer react scroll scroller scrolling scrollto

scroll-js's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar fr33maan avatar joshrishell avatar markcellus avatar tadatuta avatar umamialex 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  avatar

scroll-js's Issues

Feature Request: `cancel` method

It would be great to have a method to call to forcibly cancel a scroll that has already been initiated using scroll-js. This way, if a user starts manually scrolling or performs a pointer/touch event during the scroll, I can cancel the scroll to freeze the frame at the time they trigger that event.

This would be similar to the cancelScroll method from @cferdinandi's smooth-scroll package.

Behavior of `behavior`

Hi,

I find the behavior option a little confusing, maybe it would be convenient to describe the difference between auto and smooth, which is (according to the draft):

  • auto: The scrolling box is scrolled in an instant fashion.
  • smooth: The scrolling box is scrolled in a smooth fashion using a user-agent-defined timing function over a user-agent-defined period of time. User agents should follow platform conventions, if any.

Regarding the code:

https://github.com/mkay581/scroll-js/blob/e3063f824f1925b386b3fc2a0a59d2abb656e2a4/src/scroll.ts#L136-L143

It looks like it is not draft compliant (or maybe I'm wrong πŸ˜…). But I have no idea on how to retrieve this info from the user agent.

For me the current implementation is completely okay, but I am missing a little bit of explanation at the README.

What is your opinion @mkay581? Should I submit a PR adding this explanation to the README?

Thanks!

Offset option

When scrolling to an element with a fixed header, you'd need to have an option to specify an offset. The offset may vary between viewports or can be expanding once you scroll up, so it should also support a callback function.

Errors with brunch

I am using Brunch.io to pack all the code together, and when installing this via npm, I get the following error:

20 Jul 17:01:47 - error: undefined of node_modules/scroll-js/src/scroll.js failed. rror: 'import' and 'export' may only appear at the top level (6:0)

I have no idea what's causing this, and I've never come across this before.

If I can provide any information you need, please ask.

On nextjs it runs in development mode.

Install it on next js will work like development mode.

Cannot find module 'core-js/modules/es.object.to-string.js' Require stack: - /app/node_modules/scroll-js/dist/scroll.common.j

Container.contains is not a function

This block of code is throwing not a function:

     if (!container.contains(el)) {
                errorMsg = 'Scroll.toElement() was passed an element that does not exist inside the scroll container';
                console.warn(errorMsg);
                return Promise.reject(new Error(errorMsg));
            }

Duration: 0?

Is there a way to instantly scroll, without an animation/transition? Currently have this:

      scroll.toElement(element, { duration: 0 });

But doesn't seem to work. πŸ‘Ž

scrollIntoView not working in IE

I'm not able to get this working in IE. I'm getting this error:

SCRIPT5007: Object expected

It looks like IE is still expecting domElement.scrollIntoView instead of scrollIntoView(domElement...

Scrolling always starts at the top for Chrome and Firefox

Expected Behaviour

Scroll.toElement starts scrolling at current position

Actual Behaviour

On Chrome and Firefox the scroll position is reset to the top and starts there.

Usage

const element = document.getElementById(id);
const scroll = new Scroll(document.body);
scroll.toElement(element)

Details

This is most likely related to the weird fact that document.body.scrollTop is always 0 on Chrome and Firefox

Hacky fix

This works for us:

const element = document.getElementById(id);
const scroll = new Scroll(document.documentElement.scrollTop > 0 ? document.documentElement : document.body);
scroll.toElement(element)

Notice: I know this will use document.body when the page is not scrolled. This prevents you from initializing the scroll object only once.


This duplicates #25 - sorry

Support for stop points

Not really an issue, sorry.

I am looking for a native script that can manage scrolling and stopping at specific points along the page, like screens.

We have each section full height, and the scroll behaviour is required to stop at the edge of each section.

Can this be done with this script?

Import error "cannot find module"

Hi, when I try to import your module

import { scrollTo, scrollIntoView } from 'scroll-js';

I get the following error:

Cannot find module core-js/modules/es.object.to-string.js imported from ./node_modules/scroll-js/dist/scroll.common.js

I have no idea what this could mean... Any idea how I could get this to work?
Thank you in advance.

PS: I am using Vite with SvelteKit if thatβ€˜s of any help

IE11 Support

Hey,

Does this package supports IE11? I have tried it today but can't make it work on IE11 due to an error. SCRIPT1006: Expected ')'
Not sure if it's my webpack setup breaking stuff or it just doesn't work currently on IE.

Thanks

Massive NPM package

Just wanna let you know that I tried to use scroll-js via NPM yesterday, but was shocked to wait for 240 secs till about 3 hundred dependencies get installed. Maybe Bower package is not so heavy, but Bower is no being abandoned.
Are all those babel dependencies necessary? All I really need is one JS file. I believe the library works great, at least as I read the description, but the collateral damage of having about 300 deps installed is no for me.

Feature Request: `scrollBy` method

@markcellus, thanks for creating such a versatile package to handle more complex and programmatic scrolling needs.

Would you consider adding a scrollBy method that accounts for the current scroll offset of the target, similar to how the browser's built-in APIs offer both scrollTo and scrollBy methods?

Thanks!

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.