Finally, a "back to top" button that behaves like a real elevator.

Overview

elevator.js

Finally, a "back to top" button that behaves like a real elevator, by adding elevator music to quietly soothe the awkwardness that can ensue when being smoothly scrolled to the top of the screen.

This is very serious stuff, here's a demo!

Instructions

Elevator.js is a stand alone library (no jquery, or the likes) so usage is pretty straight forward. All styling of elements is up to you. Elevator.js only handles the audio management, and the scroll functionality!

JS

Elevator.js lives entirely within the js realm, which makes things fairly simple to use.

You'll need to create a new instance of Elevator, and pass it some audio elements.

<script>
// Elevator script included on the page, already.

window.onload = function() {
  var elevator = new Elevator({
    mainAudio: '/src/to/audio.mp3',
    endAudio: '/src/to/end-audio.mp3'
  });
}

// You can run the elevator, by calling.
elevator.elevate();
</script>

You can also add an "element" option, clicking this element will invoke the "Scroll to top" functionality, we all love and crave.

<div class="elevator-button">Back to Top</div>

<script>
// Elevator script included on the page, already.

window.onload = function() {
  var elevator = new Elevator({
    element: document.querySelector('.elevator-button'),
    mainAudio: '/src/to/audio.mp3',
    endAudio: '/src/to/end-audio.mp3'
  });
}
</script>

If you don't want to scroll to the top, a custom target can be specified by adding a "targetElement" option:

<div class="elevator-button">Take the elevator to the target</div>

<script>
// Elevator script included on the page, already.

window.onload = function() {
  var elevator = new Elevator({
    element: document.querySelector('.elevator-button'),
    targetElement: document.querySelector('#elevator-target'),
    mainAudio: '/src/to/audio.mp3',
    endAudio: '/src/to/end-audio.mp3'
  });
}
</script>

If you want to scroll to a point on the page with some extra padding on the top, simply add the "verticalPadding" option:

<div class="elevator-button">Take the elevator to the target</div>

<script>
// Elevator script included on the page, already.

window.onload = function() {
  var elevator = new Elevator({
    element: document.querySelector('.elevator-button'),
    targetElement: document.querySelector('#elevator-target'),
    verticalPadding: 100,  // in pixels
    mainAudio: '/src/to/audio.mp3',
    endAudio: '/src/to/end-audio.mp3'
  });
}
</script>

If you're really serious (boring), you don't have to use audio... and can also set a fixed time to scroll to the top

<div class="elevator-button">Back to Top</div>

<script>
// Elevator script included on the page, already.

window.onload = function() {
  var elevator = new Elevator({
    element: document.querySelector('.elevator-button'),
    duration: 1000 // milliseconds
  });
}
</script>

If you use elevator.js in combination with other code, you might want to use callbacks

<script>
window.onload = function() {
   new Elevator({
       element: document.querySelector('.elevator-button'),
       mainAudio: '/src/to/audio.mp3',
       endAudio: '/src/to/end-audio.mp3',
       duration: 5000,
       startCallback: function() {
         // is called, when the elevator starts moving
       },
       endCallback: function() {
         // is called, when the elevator reached target level
       }
   });
}
</script>

NPM

The package is also available via NPM

License

Elevator.js is covered by the MIT License.

Audio in the Demo was bought via Pond5, you will need to license your own.

Copyright (C) ~ Tim Holman ~ [email protected]

Comments
  • Breaks on IE8 due to lack of Audio API support

    Breaks on IE8 due to lack of Audio API support

    Elevator breaks on IE8 and I'm blessed to work on a product that still supports it.

    Will PR a fix today (basically checking for the lack of it and return afterwards).

    opened by joaocunha 8
  • Tabbing away breaks

    Tabbing away breaks

    1. Go http://tholman.com/elevator.js/
    2. Scroll down.
    3. Click Back to Top. Music plays.
    4. Open new tab and go to your favorite site that's SFW.
    5. Music still plays on the other tab.
    6. Yea feels so good~
    7. Come back to elevator page.
    8. Ding!
    9. But still at the bottom.
    opened by saml 8
  • .back-to-top class is hidden by the ad-blocker

    .back-to-top class is hidden by the ad-blocker

    I've noticed that the nice "go to top" button has been hidden by the adblocker because of 'back-to-top' class it has. Can this class name be changed to something more ad-blocker friendly?

    opened by ghost 7
  • No

    No "ding" in Mobile Safari

    Hey, I know this is mostly a gag so you might not care, but you don't get the "ding" in Mobile Safari. My guess is that it's the fact that iOS requires user intervention to play audio on websites? I'm not sure if there's a way around it.

    opened by alexlafroscia 5
  • add tags for each version

    add tags for each version

    would you please consider adding tags for each version so that we can add your lib on https://cdnjs.com with git auto-update. thank you very much! https://github.com/cdnjs/cdnjs/issues/5529

    opened by maruilian11 4
  • Fixed errors in the README.

    Fixed errors in the README.

    The example given in the README to trigger the elevator from Javascript was not working.

    In :

    var elevator = new Elevator ({ ... });
    

    the elevator variable is an object resolved as main {} by Chrome. Thus calling elevator.elevate () raises an error because elevator doesn't contains such a function. This is working :

    Elevator.elevate ();
    
    opened by Tuetuopay 4
  • Fade-in for music

    Fade-in for music

    Added a 1 second fade-in in the demo track, and reduced volume by about 10%. I saw the earlier thread about it being a personal decision, but I think the slight fade helps with the initial surprise.

    opened by gyanl 3
  • Cancel elevation if user moves scrollwheel

    Cancel elevation if user moves scrollwheel

    Industry experts agree that user input should not be ignored for more than 100ms: https://docs.google.com/document/d/1bYMyE6NdiAupuwl7pWQfB-vOZBPSsXCv57hljLDMV8E/edit

    Elevation should be voluntary and consensual

    opened by JoshuaWalsh 3
  • [bugfix] move target position calculation from init to elevation-time

    [bugfix] move target position calculation from init to elevation-time

    I noticed an incorrect edge-case concerning my earlier contribution of custom scroll targets: the endPosition for the scrolling was calculated inside init, which could potentially lead to incorrect scroll positions if there are any DOM reflows between initialization and actual elevating.

    As a fix, I introduce an updateEndPosition function which is called once before the elevate or any immediate scroll actions.

    As a necessary by-product, inside init, targetElement (a new top-level variable) is saved instead of endPosition. No changes in the interface however.

    Additionally, the default duration calculation was not updated to consider the differing end positions, this is also amended by this PR.

    opened by ditam 2
  • Fix license note

    Fix license note

    Creative Commons is an organisation, not a license. Even it's linked to the website with the full license (name+version), it should be done the correct way. And even it may just be a demo, too many people don't licensing their stuff correctly, so be a good example =)

    opened by Croydon 2
  • Feature to have the elevator to go down

    Feature to have the elevator to go down

    This library is probably the most interesting scroll-to-top implementation, but do you think you'll ever add a feature to have the elevator go down as well? I know this was an issue that was closed in 2015, but maybe you'll reconsider implementing this feature now?

    opened by pranavjoy 0
  • Multiple Back To Top Support

    Multiple Back To Top Support

    I'm a true novice, and tried using the Back To Top feature multiple times on the same page. This was for an FAQ, which has multiple sections. At the end of each FAQ section I wanted to place a div elevator class that triggered the elevator. However, when I switched to querySelectorALL it broke the feature. I worry that I'm either doing something stupid, or that the code has to be updated to support using an array of elements on the same page? Love the 'easter egg' feature you made, but would love the readme to be updated to support multiple on the same page.

    opened by oatmealr82 0
  • Slow scrolling in Chrome

    Slow scrolling in Chrome

    Firstly, thanks for this great project! :)

    I implemented it on my website (https://uplink.tech/) but noticed the scrolling is a bit weird in Chrome (v83 on macOS): first it scrolls very slowly, and then very quickly. In Firefox and Safari it works fine.

    What can I do to debug this further?

    opened by manuelmeurer 13
  • had a laughter burst

    had a laughter burst

    thx for making my day, i didnt know what to expect when i came from hackernews and scrolled down, until clicking that button made me really laugh out loud :) @tholman

    opened by mikulabc 0
Releases(1.0.1)
Owner
Tim Holman
Tinkerer, tuner & tamperer.
Tim Holman
Elevator Pitch is a site to organize group projects based on ideas, rather than individuals

Elevator Pitch is a site to organize group projects based on ideas, rather than individuals. It allows users to create Spaces within which you can pitch an idea. Other users can browse those ideas and sign up as interested in contributing, or add comments to ask questions to the idea pitcher.

J. Michael Brown 7 Mar 23, 2022
Very useful website application to memorize all the tasks of the day, mark the complete ones, organize them by importance and finally delete them.

To Do List Very useful website application to memorize all the tasks of the day, mark the complete ones, organize them by importance and finally delet

Gonzalo Medina 3 Jul 29, 2022
Finally, a simple, lightweight (0.6kb), pure JavaScript image lazy loader that even works in IE* using the IntersectionObserver API

Simply Lazy A simple & lightweight (0.6kb), pure JavaScript image lazy loader that even works in IE* utilizing the built in IntersectionObserver API i

Max 5 Dec 26, 2022
A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view.

Strapi Preview Button A plugin for Strapi CMS that adds a preview button and live view button to the content manager edit view. Get Started Features I

Matt Milburn 53 Dec 30, 2022
Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback

Dynamic BS5 Modal Box Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback Insta

null 5 Oct 23, 2022
pjax is a jQuery plugin that uses ajax and pushState to deliver a fast browsing experience with real permalinks, page titles, and a working back button.

pjax = pushState + ajax pjax is a jQuery plugin that uses ajax and pushState to deliver a fast browsing experience with real permalinks, page titles,

Chris Wanstrath 16.8k Jan 5, 2023
Hey There! 🙌 🤾 that ⭐️ button if you like this boilerplate.

Hey There! ?? ?? that ⭐️ button if you like this boilerplate. A boilerplate for Node.js App. Contents Global Requisites App Structure Install, Conf

J.D. 7 Dec 5, 2022
A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp.

Basic2Lisp A "Basic-to-Lisp" compiler. But Basic is not real Basic, and Lisp is not real Lisp. Syntax Print-Sth Put some-value to standard output. PRI

Hana Yabuki 5 Jul 10, 2022
A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebWorker like neither of those.

Amuchina A work-in-progress HTML sanitizer that strives for: performance like window.Sanitizer, readiness like DOMPurify, and ability to run in a WebW

Fabio Spampinato 9 Sep 17, 2022
This extension injects a button to the Google Drive WebUI.

This extension injects a button to the Google Drive WebUI. When clicking on it the current folder id is send to your gogdl-ng instance. It was developed and tested on the latest version of Mozilla Firefox and Chrome.

null 5 Jul 13, 2022
TRAB is a Chrome extension that gives you a single button to mark tweet as spam, and block the tweet's creator

TRAB - Tweet Reporter and Blocker TRAB is a Chrome extension that gives you a single button to do two things with a single click: Mark a Tweet as spam

Amit Ruparel 16 May 4, 2022
MPVPlay is an MPV play button integration for YouTube Web.

MPVPlay MPVPlay is a combination of a `.desktop` file and a userscript that allows you to play YouTube videos directly in MPV with the click of a butt

Fülöp Tibor 2 Apr 17, 2022
This project is built with JavaScript, Webpack, HTML & CSS, Leaderboard api. When user clicks on Refresh button it hits the api and responds with the data, The user can also post data to the api

leaderboad Description the project. this project is about the leaderboad i did during Microverse to build a website for adding Data to the API and fet

Emmanuel Moombe 4 May 30, 2022
Garfield Whatsapp 🐼 Userbot is a button 🦋 bot that operates 24×7 Hour powered By X-nodes server

GARFIELD WHATSAPP USER BOT LATEST VERSION (Button Update ?? And 24×7 hour Working ?? ) New Features and upgrades v8.0 ?? ?? Bot continues to work even

NOIZ Ξ 33 Dec 4, 2022
A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

A Virtual Interactive Keyboard which replicates every key you press and a Text-Area in which everything is written and can be copied to the clipboard with a click of a button.

Devang Joshi 1 Mar 1, 2021
A button to POST an emoji to an endpoint.

<open-heart> A button for the Open Heart Protocol. ?? Highly experimental. Tag a version to avoid unexpected changes. Usage <!-- Include `OpenHeartEle

ddddddddʣzzz 20 Nov 3, 2022
Kuldeep 2 Jun 21, 2022
A plugin for Obsidian (https://obsidian.md) that adds a button to its search view for copying the Obsidian search URL.

Copy Search URL This plugin adds a button to Obsidian's search view. Clicking it will copy the Obsidian URL for the current search to the clipboard. T

Carlo Zottmann 6 Dec 26, 2022
A to-do list Web application that lets the user add, remove and reorder to do lists and checks a task when completed with a button to delete all completed task

TO DO LISTS A Web application that lets the user add, remove and reorder to do lists Built With Html,JS,CSS Webpack and other dependencies Git, Github

Promise Okechukwu 14 Nov 1, 2022