• Stars
    star
    885
  • Rank 49,770 (Top 2 %)
  • Language
    CSS
  • License
    MIT License
  • Created over 9 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A replacement for infinite scrolling.

lavalamp.js

A replacement for infinite scroll. Works both ways (next and previous).

Demo

LavaLamp screenshot

HTML structure

  • a.button#previous = Load previous
  • your page content
  • a.button#next = Load next
  • a#lavalamp including a span = Loading

How it works

There are 2 buttons: #previous and #next, that encapsulate the page.

When either of them is clicked, the #lavalamp HTML element covers the whole viewport while both the content of the page and the scroll position are updated.

Because all 3 elements look the same, it looks like the button clicked is expanding to cover the page.

For example, if you click next:

  • the lavalamp is displayed, and initially positioned on top of the next button
  • the lavalamp's bottom and height properties are animated through CSS to cover the whole page
  • scrolling is temporarily disabled
  • the page scrolls to the top
  • when the new content is loaded, the lavalamp is animated upwards to match the previous button
  • the lavalamp is hidden and reset, scrolling is re-enabled

Additional details

  • For the sake of the demo, I use a setTimeout to simulate an Ajax call (the content remains unchanged).
  • I also use a timeout after the last animation. I could use to detect CSS animation ends, but a timeout provides more flexibility, and prevents having to deal with browser inconsistencies. Plus, it's only 1 line.
  • The previous button is the first child, the next button is the last child. It's possible to have other elements before and/or after, but then the illusion of the clicked button expanding is harder to execute because the lavalamp needs to be positioned exactly on the clicked button (which in the case, would not be exactly at top: 0; or bottom: 0;). It's possible to change the CSS animation values if needed though.
  • The viewport is the whole body. It's possible to have a fixed header and/or footer as well, because the lavalamp is fixed as well. So, if you have a header that's 70px high, just change the CSS animation's top values to be 70px, not 0; (GIF demo coming soon).

Is this production-ready?

Kind of. The CSS animations should work well. The JS only takes care of updating the CSS classes, showing/hiding the lavalamp, and scrolling up and down. But it can be improved.

This repo is just a demo to showcase the intended user experience. Feel free to implement as you wish.

License

The MIT License (MIT)

Copyright (c) 2014 Jeremy Thomas

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

bulma

Modern CSS framework based on Flexbox
CSS
47,555
star
2

css-reference

CSS Reference: a free visual guide to the most popular CSS properties
HTML
4,826
star
3

web-design-in-4-minutes

Learn the basics of web design in 4 minutes
HTML
4,322
star
4

minireset.css

A tiny modern CSS reset
JavaScript
2,715
star
5

marksheet

Free tutorial to learn HTML and CSS
JavaScript
1,008
star
6

html-reference

HTML Reference: a free guide to all HTML5 elements and attributes
HTML
956
star
7

wysiwyg.css

A tiny CSS for generated HTML or Markdown content
Sass
710
star
8

javascript-in-14-minutes

Learn the basics of JavaScript in 14 minutes
CSS
548
star
9

juketube

A YouTube jukebox built with AngularJS
JavaScript
278
star
10

bulma-start

Start package for Bulma
CSS
273
star
11

bulma-website

[DEPRECATED] Website for the Bulma CSS framework
CSS
40
star
12

hacker-news-dark-mode

Hacker News Dark Mode
HTML
18
star
13

bulma-versions

Bulma Versions
HTML
8
star
14

euro-2016-calendar

Simple mobile-friendly Euro 2016 calendar
CSS
6
star
15

how-css-works

CSS
5
star
16

social-media-assets

A simple repository of colors & logos from popular social websites.
CSS
5
star
17

monokai-extended-colors

Monokai Extended Colors in HTML
HTML
3
star
18

amp

AMP (Accelerated Mobile Pages) test
CSS
3
star
19

css-art-science

Un parcours initiatique à l'intégration Web
CSS
3
star
20

theme-generator

CSS
2
star
21

bbxdesign

WordPress Theme for my blog and portfolio
CSS
2
star
22

buttonizer

Something something
JavaScript
2
star
23

premonish

Predict which DOM element a user will interact with next.
JavaScript
1
star
24

bbxworld

First ever bbx website
HTML
1
star
25

amp-homepage

CSS
1
star
26

toast

Ghost Theme
CSS
1
star
27

grumpy-cat

Grumpy Cat
HTML
1
star
28

barn-dor

The Barn d'Or Award
CSS
1
star
29

grandourse

Discourse Theme
CSS
1
star
30

sochi-2014-calendar

A simple calendar for the Sochi 2014 Olympics
JavaScript
1
star