Code Monkey home page Code Monkey logo

material-scrolltop's Introduction

npm version stars NPM Downloads Join the chat at https://gitter.im/material-scrolltop/Lobby HitCount volkswagen status

Material ScrollTop Button

Upgrade instructions 1.x → 2.x

Lightweight, Material Design inspired button for scroll-to-top of the page (jQuery plugin).

Just hit the button to smoothly scroll back to the top of the page. Here's the demo.

  • Lightweight
  • Material Design inspired
  • With ripple effect
  • Smoothly animated
  • Customizable
  • With some useful options...
  • jQuery + CSS, (TypeScript + SCSS)

Demo animation

Demo (example)

Watch this: https://bartholomej.github.io/material-scrolltop/

Install

Via yarn or npm

yarn add material-scrolltop

Manual install (download)

If you want the latest stable version, get the latest release from the releases page and use dist folder.

Usage

Include the files as shown in the code snippets below and you're done.

NOTE: The only dependency for this plugin to work is jQuery library (don't forget!)

In your <head> add:

<!-- Material ScrollTop stylesheet -->
<link rel="stylesheet" href="dist/material-scrolltop.css" />

<!-- material-scrolltop plugin -->
<script src="dist/material-scrolltop.js"></script>

Then, before your closing </body> tag add:

<!-- material-scrolltop button -->
<button class="material-scrolltop" type="button"></button>

<!-- Initialize material-scrolltop (minimal) -->
<script>
  $('body').materialScrollTop();
</script>

Settings

Option Type Default Description
revealElement string body Reveal button when scrolling over specific element
revealPosition string top Element position for reveal button ('top' or 'bottom')
padding number 0 Adjusts little ups and downs in scrolling (can be negative number)
duration number 600 Determining how long the animation will run
easing string 'swing' Indicating which easing function to use for the transition animate()
onScrollEnd Function() false A function to call once the animation is complete

Example (advanced usage)

$('body').materialScrollTop({
  // Scroll to the top of <body> element ...
  padding: 100, // ... and add padding 100px
  revealElement: 'header', // Reveal button when scrolling over <header> ...
  revealPosition: 'bottom', // ... and do it at the end of </header> element
  duration: 600, // Animation will run 600 ms
  easing: 'swing', // Do it with swing animation
  onScrollEnd: function () {
    // Give me some log when animation ends
    console.log('This is the end, my only friend, the end...');
  },
});

Folders

material-scrolltop/
├── src/
|   ├── icons/
│   |   └── top-arrow.svg
│   ├── material-scrolltop.scss
│   └── material-scrolltop.ts
├── dist/
|   ├── icons/
│   |   └── top-arrow.svg
│   ├── material-scrolltop.css
│   └── material-scrolltop.js
└── demo/
    ├── ...
    └── index.html
    └── examples/

src/ (for development)

TypeScript + SCSS source files

.ts, .scss

which are NOT executable in browser

dist/ (for production)

JavaScript + CSS

executable in browser and compiled from src/ folder with command yarn build

demo/ (example page)

In this folder you can see an example in real use.

Customization

Colors, sizes and stuff

Using SASS (this file in 'src' folder), you can simply edit default styles, colors, position and customize plugin to fit your needs. 👍 (Or just edit directly css stylesheet)

Hint: Modify scss file, run yarn build and see the demo.

Icons

SVG

You can change svg icon in icons/ directory.

Custom text or sign

  1. Turn off svg icon as sass variable: $mst-icon: false
  2. Build your new stylesheet yarn build (now without svg icon)
  3. Put your new sign or text inside html <span> element like this:
<button class="material-scrolltop" type="button">
  <span></span>
</button>

Dependencies

jQuery 1.7+

Upgrade instructions

Version 1.x → 2.x

Version 2.x.x contains some breaking changes:

  • src/ folder now contains source files .scss + .ts which are NOT executable in browser.
  • dist/ folder contains compiled .css, .js, ... (executable in browser!)

Old versions

Old version is still available:

  • Dev branch: 1.x
  • npm package: yarn add material-scrolltop@1-latest

Application

License

Copyright © 2015 - 2020 Lukas Bartak

Proudly powered by nature 🗻, wind 💨, tea 🍵 and beer 🍺 ;)

All contents are licensed under the MIT license.

material-scrolltop's People

Contributors

bartholomej avatar dependabot[bot] avatar gh640 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

material-scrolltop's Issues

npm install do not include icons/

when I use

$ npm install material-scrolltop --save-dev or yarn

I found the package do not include src/icons/top-arrow.svg, so I compiled by webpack got the error.
but I use bower it's work fine.

my temporary solution:
copy the SVG file into the folder and compile it.

Plugin working with jquery 3.2.1?

Hi
The console on chrome browser gives me an error when I click the top button:

material-scrolltop.js:46 Uncaught TypeError: $(...).animate is not a function
at HTMLButtonElement. (material-scrolltop.js:46)
at HTMLButtonElement.dispatch (jquery-3.2.1.slim.min.js:3)
at HTMLButtonElement.q.handle (jquery-3.2.1.slim.min.js:3)

I am using bootstrap setup

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" `crossorigin="anonymous"></script>`

Feature request: both top and bottom

Hi is it possible to top and bottom feature

if user top of the page bottom icon will visible and click on bottom it will move to bottom of the page

Click event might need two taps on mobile browsers

I heavily modified the button markup and due to :hover styles the first tap on mobile did not trigger the click event on the button.

I suggest modifying the following line
_.btnElement.click(function() {
to
_.btnElement.on('mousedown touchstart',function() {

That would make the click event fire under any circumstances.

Consider tweaking your build process

Problem:
node-sass does not like the following:

  1. importing css
  2. importing file with explicit extension.
  3. gets confused when there are files with same basename, but extensions css, and scss.

If you save material-scrolltop.css to, say, dist/, then this issue would be resolved.

Issue in Firefox

Hello, kinda a newbie here. Loved your script and edited it to work with my website but it seems to not be working in Firefox and I cannot figure out why :/ It works edited offline on your demo, but once I upload it to my website it gets broken in FireFox. Here is the website in question: http://dulic.me/about
Would love it if you could help me out. Thanks.

CSS source map missing

CSS source map URL is declared but the actual .css.map file is missing.

/*# sourceMappingURL=material-scrolltop.css.map */

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.