npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

smile-universal-parallax

v1.3.3

Published

Easy parallax plugin using vanilla javascript. Works on mobile devices (really). Lightweight (2kb). Cross browser compatibility

Downloads

41

Readme

npm version Package Quality

Universal Parallax

Easy parallax plugin using pure javascript. Lightweight (2kb) and cross browser compatibility - including mobile platforms (iOS, Android).

See demo

:zap: Features

  • Easy setup
  • Pure JavaScript
  • Adaptive height
  • Works on mobile devices
  • Lightweight (2kb minified)

:floppy_disk: Install

$ npm i universal-parallax -S or yarn add universal-parallax

:rocket: Setup

#1

Choose between:

  • Include this in your <head> section
<link href="node_modules/universal-parallax/dist/universal-parallax.min.css" rel="stylesheet">
  • Or add this CSS
.parallax__container {
	clip: rect(0, auto, auto, 0);
	height: 100%;
	left: 0;
	overflow: hidden;
	position: absolute;
	top: 0;
	width: 100%;
	z-index: -100;
}

.parallax {
	position: fixed;
	top: 0;
	-webkit-transform: translate3d(0, 0, 0);
	transform: translate3d(0, 0, 0);
	-webkit-transform-style: preserve-3d;
	transform-style: preserve-3d;
	width: 100%;

	/* BG behaviour */
	background-position: center;
	background-repeat: no-repeat;
	background-size: cover;
}

:zap: BG behaviour in seperate class gives more flexibility controlling them :zap: SASS version available in /dist folder

#2

If <section> is your container, make the parallax element inside it

<section>
	<div class="parallax" data-parallax-image="path/to/your_image">
</section>

:zap: You can also use background-image to define your image instead of using data-parallax-image=""

#3

Static HTML

Include the script to your project

Put the script at the bottom of your markup right after jQuery

<script src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>
<script src="node_modules/universal-parallax/dist/universal-parallax.min.js"></script>

Load

Webpack

Add jQuery via the "webpack.ProvidePlugin" to your webpack configuration:


//...
plugins: [
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery',
      'window.jQuery': 'jquery'
    }),
],
//...

Load the required stylesheet and JS:

import 'universal-parallax/dist/universal-parallax.min.css';
import 'universal-parallax';

#4

Initialize the JS function

<script>
$(document).ready(function(){
  $('.parallax').universalParallax();
});
</script>

That's it! :checkered_flag:

Custom speed

You can change the parallax speed; the higher the number, the slower the parallax effect

$(document).ready(function(){
     $('.parallax').universalParallax({
        speed: 6.0,
    });
});

:zap: speed: 1 is the minimum value before the background image is fixed

Tips

Opacity

If you want your backround color to shine through or dampen the image without making it a .png - just add transparency to it

.parallax {
	opacity: 0.5;
}