Code Monkey home page Code Monkey logo

preact-scrollchor's Introduction

preact-scrollchor

The improved preact fork of react-scrollchor for scrolling to markup elements and/by setting the #hash. Scrollchor is a mix of Scroll and Anchor, a joke name for a useful component.

hash is the id of a HTML tag on current page.

If you're a react-person definitely check out the original version, I mainly didn't want to bother adding preact-compat and disliked quite a few aspects of the implementation.

Installation

npm install preact-scrollchor --save

Usage

import Scrollchor from "preact-scrollchor"

export default props => (
  <div>
    <ul>
      <li>
        <Scrollchor to="#sample-code">Sample</Scrollchor>
      </li>
      <li>
        <Scrollchor to="footer">SignUp</Scrollchor>
      </li>
    </ul>
    <div id="sample-code" />
    <footer id="footer" />
  </div>
)

Custom animation

Animation behavior can be customized:

<Scrollchor to="#aboutus" animate={{ offset: 20, duration: 600 }}>
  Home
</Scrollchor>

Default animation settings

{ offset: 0, duration: 400, easing: easeOutQuad }

This setting is equivalent to default jQuery.animate easing: swing

More Easing functions

before and after Animate callbacks

Use this callbacks to trigger behaviours like, for example, update state, load async stuffs, etc.

<Scrollchor to="#aboutus" afterAnimate={() => updateState(this)}>
  Home
</Scrollchor>

Simulate click API

Scrollchor includes a dedicated API to invoke the scroll behavior programmatically using simulateClick()

License

ISC

preact-scrollchor's People

Contributors

bysabi avatar ltetzlaff avatar sbrk avatar kambing86 avatar jeanchung avatar

Stargazers

Andy Zeigert avatar Matthew Hartman avatar Hector Romo avatar Lukas avatar

Watchers

 avatar

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.