Giter VIP home page Giter VIP logo

animated-scroll-to's People

Contributors

adam187 avatar chenroth avatar cyberhazard avatar davidneios avatar dependabot[bot] avatar fr8train avatar idready avatar jahil-khalfe avatar johnsoncheg avatar jrwebdev avatar maximilianmairinger avatar stanko avatar thomasjonas avatar twentyrogersc avatar vlio20 avatar weotch 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

animated-scroll-to's Issues

"onComplete" never gets called when user interrupts scroll animation

When you set cancelOnUserAction to true and after scroll animation is interrupted by user's action, the onComplete never gets called. It would be nice to know if animated completed even if it was interrupted in the middle. I would like to help with PR, so just let me know if that's a good idea.

handleUserEvent = function() {
removeListeners();
cancelAnimationFrame(requestID);
};

Horizontal scrolling

I was hoping to use this to implement a horizontal carousel. I was sad to see that it only supports vertical scrolling.

Would this be difficult to add?

Speed can't be changed

It doesn't seem to matter which values I assign to option speed: the animation remains identical in all cases. Also tried to play around with maxDuration and minDuration. Nothing makes the animation speed change.

const defaultOptions = {
  maxDuration: 2000,
  minDuration: 2000,
  speed: 3000
}

const defaultOptions = {
  speed: 5000
}

const defaultOptions = {
  maxDuration: 2000,
  speed: 8000
}

animatedScrollTo(el, defaultOptions)

Compatible with react

Hi,Is this library compatible with react ?..... i mean does it follow the guidelines of react of not manipulating the DOM directly ?

Feature request: Implement Promise interface.

It would be very useful to have animateScrollTo() return a Promise object. This would help a lot in environments where scrolling is part of a bigger animation path.

animateScrollTo(node, { offset: -100 })
   .then(node => console.log('scrolled to', node))

can you remove comment script tag

comment script tag cause some problem when i use in iframe in development mode, can you remove it?
in 352, thank you.

<script src="https://unpkg.com/es6-promise/dist/es6-promise.auto.min.js"></script>

No trigger

Hello, I'm trying to make your plugin work for me without any chance for now..

Here is my vanilla JS code

Capture d’écran 2020-04-20 à 17 12 55

And render HTML in google chrome console,

Capture d’écran 2020-04-20 à 17 13 39

In plain english, what I am trying to achieve is :

When I click on the button with the class js-trigger, the container #section--vertical will scroll to the element #slide__project--first

Perhaps I am using your function animateScrollTo wrong ...

Can you help me out ?

Custom easing

Animated scroll is perfect for my use case except I would like to use a different easing curve. Have you considered adding support for custom curve functions? If not do you have any advice on the best way to modify the code to alter the current easing?

Many thanks in advance.

Chrome console warning

I'm getting this warning in my Chrome inspector console from this package:

[Violation] Added non-passive event listener to a scroll-blocking 'wheel' event. 
Consider marking event handler as 'passive' to make the page more responsive.

What it is

Solution

I'm going to try to create a PR soon with a fix.

if element and cancelOnUserAction passed the whole page can't scroll

Hello,
I had this issue while working with the library, I pass an horizontal element to be animated and also cancelOnUserAction: false but the whole page loses the scroll behaviour.

I fixed it by changing the window listeners of wheel, scroll and touch start to options.element

Screen Shot 2019-09-13 at 7 45 32 PM

Typescript typings are out of date and not stored in the the repo

It looks like the typings for this library are not properly 'done' yet. Looks like it was only updated to use typescript 30 days ago.

The original index.d.ts typings need to be removed and the the up to date typings need to be defined.

Looks like the typings in npm package are the generated ones by tsc --declaration (they are included in the npm package)
https://github.com/Stanko/animated-scroll-to/blob/master/package.json#L12

And the type definitions are defined by package.json
https://github.com/Stanko/animated-scroll-to/blob/master/package.json#L6

It however also looks like the output folder ./lib is git ignored which is why they're probably not in the repo.
https://github.com/Stanko/animated-scroll-to/blob/master/.gitignore#L9

To do

  1. Exclude 'lib' from .gitignore
  2. Include the animated-scroll-to.d.ts type definition in the repo
  3. Delete v1 index.d.ts type definition

Limit scroll directions

Hello,

When you pass an element to animatedScrollTo(myElement) it will scroll to it in both direction (horizontal and vertical), but in my case i wanted to scroll only vertically to that element.

Do you think it's possible to add properties which limits the scroll only in one direction?

v2 breaks SSR apps

The new 2.0.+ versions reference window when requiring the package. This breaks SSR apps, as window is not defined when running in a node environment. In 1.2.2 the problem was not present. It is very easy to reproduce.

mkdir anim-ssr-bug
cd anim-ssr-bug
npm install animated-scroll-to
node
> const a = require("animated-scroll-to")

result:

ReferenceError: window is not defined
    at Object.<anonymous> (/Users/csorfab/Web/test/node_modules/animated-scroll-to/lib/animated-scroll-to.js:95:22)
    at Module._compile (internal/modules/cjs/loader.js:688:30)
...

Using with Typescript and useRef hook throws a type error

Trying to do a simple scroll to element using useRef in a Typescript project but getting the following error:
Screen Shot 2022-10-09 at 6 23 56 PM

Code looks like this.

const Home: NextPage<Props> = ({ pagedata }) => {

  const infoRef = useRef<HTMLElement>(null);

  return (
    <>
      <nav>
        <button
          onClick={() => {
            animateScrollTo(infoRef.current);
          }}
        >
          Information
        </button>
      </nav>

      <main className={styles.main}>
        <Projects data={pagedata ? pagedata.data.projects : null} />
      </main>
      <section ref={infoRef} className={styles.info} id="information">
        <InfoSection data={pagedata} />
      </section>
    </>
  );
};

export default Home;

Not sure what I'm doing wrong here, seems to want a number as the parameter, but I can't change the definition on the ref or it gets upset that I'm passing an element.

requestAnimationFrame is not defined

I have an issue with old android 4.3 native browser. requestAnimationFrame is not supported for that version.

My suggestion is create a function which will check for requestAnimationFrame.
var requestAnimFrame = (function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(callback){window.setTimeout(callback,1000/60);};})();

and instead of requestAnimationFrame use it requestAnimFrame

navigation with keydown is disabled

is it possible to also support navigation with the keyboard keys ?

atm in my app instead of only relying on the mouse, i also offer to use the keyboard arrow keys which is much easier and quicker than the mouse,
hoever atm the lib use the keydown event to stop the scroll

window.removeEventListener('keydown', handleUserEvent, userEventOptions);

so is there a way to add an option to enable that for those who needs it ?

Version 2 - TypeScript rewrite

This issue will be used as a main thread of communication for the version 2.

We just started, more info coming soon.

Todo

  • Setup TypeScript (module + window.animateScrollTo)
  • Refactor library
  • New method signatures
    • (y, options)
    • ([x, y], options)
    • (element, options)
  • Diagonal scroll
  • Add custom easing to options
  • Tests
    • Setup CircleCI
  • Fail silently on server
  • Two synchronous calls on the same element should cancel each other (they should)
  • Better demo

Maybe

  • TBD remove cancelOnUserAction (consider it always to be true) just defaults to true
  • Promise interface #23

Breaking Changes

  • New method signatures
  • Removed horizontal option

Can't get animateScrollTo to work when passed with option object

I have a scrollTo function which is invoked on a button click.

scrollTo = (elem) => {
    animateScrollTo(document.getElementById(elem));
};

However, when I try to add some offset to adjust for padding, it doesn't scroll at all.

scrollTo = (elem) => {
    animateScrollTo(1000, {
      offset: 100,
      element: document.getElementById(elem),
    });
  };

Set default options during import

Hi @Stanko , first of all thanks for the library, it solve a big need!
My question is about setting the default options during the import.
Is it possibile?
import animateScrollTo from 'animated-scroll-to'; window.animateScrollTo = animateScrollTo;
What i've to do before assigning it to global window object?

Compile Error on node 14

When building version 2.0.11 using node 14 and TypeScript 3.8.3, this error results:

ERROR in node_modules/animated-scroll-to/lib/animated-scroll-to.d.ts:1:33 - error TS1005: ',' expected.

1 export declare type TCoords = [x: number | null | undefined, y: number | null | undefined];
                                  ~
node_modules/animated-scroll-to/lib/animated-scroll-to.d.ts:1:63 - error TS1005: ',' expected.

1 export declare type TCoords = [x: number | null | undefined, y: number | null | undefined];

Choppy animation on the newest version of Firefox

Hello, this library has been working very well for me, but I have tested it on the latest version of Firefox (61.0b10), and it is now not animating smoothly.

I am on Debian 9.4 (64-bit). On Firefox 52.8.1 it is fine, as it is on Chromium 66.0.3359.117.

If it helps, here are some plugins that animate smoothly on the newest Firefox:

And here are some that are affected by the same problem (in case cross-comparing them helps you find the bug):

Either way, thank you for this plugin, it has a nice API and I would prefer to continue using it.

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.