Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jarallax

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jarallax

Parallax plugin for background images and videos

  • 1.9.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
increased by4.02%
Maintainers
1
Weekly downloads
 
Created
Source

Just Another Parallax

Smooth parallax scrolling effect for background images, videos and inline elements. Code in pure JavaScript with NO dependencies + jQuery supported. Youtube, Vimeo and Local Videos parallax supported.

Demo

Tested Browsers

  • IE9+
  • Safari 5.1.7+
  • Opera 12+
  • Latest browsers on Mac and Windows (Chrome, Firefox, Safari, IE, Edge)
  • Latest Chrome on Android
  • Latest Safari on iOs

Want WordPress Plugin?

Advanced WordPress Backgrounds

We made WordPress plugin to easily make backgrounds for content in your blog with all Jarallax features.

Demo: https://wp.nkdev.info/free-advanced-wordpress-backgrounds/

Download: https://nkdev.info/downloads/advanced-wordpress-backgrounds/

Install

Include Jarallax plugin. Also include jQuery before jarallax if you want to use it.

Download

Download scripts directly from this repository and link it in your HTML file

<!-- Jarallax -->
<script src="jarallax/jarallax.js"></script>

<!-- Include it if you want to use Video parallax -->
<script src="jarallax/jarallax-video.js"></script>

<!-- Include it if you want to parallax any element -->
<script src="jarallax/jarallax-element.js"></script>

CDN

Link directly from cdnjs

<!-- Jarallax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jarallax/1.9.0/jarallax.min.js"></script>

<!-- Include it if you want to use Video parallax -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jarallax/1.9.0/jarallax-video.min.js"></script>

<!-- Include it if you want to parallax any element -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jarallax/1.9.0/jarallax-element.min.js"></script>

Package managers

npm: npm install jarallax -- save

Bower: bower install jarallax --save

Supported plugins

You can add these plugins before jarallax initialize.

Set up your HTML

<!-- Background Image Parallax -->
<div class="jarallax">
    <img class="jarallax-img" src="<background_image_url_here>" alt="">
    Your content here...
</div>

<!-- Alternate: Background Image Parallax -->
<div class="jarallax" style="background-image: url('<background_image_url_here>');">
    Your content here...
</div>

Additional styles

These styles need to correct background image position before Jarallax initialized:

.jarallax {
    position: relative;
    z-index: 0;
}
.jarallax > .jarallax-img {
    position: absolute;
    object-fit: cover;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
}

Call the plugin

A. Data attribute way

<div data-jarallax data-speed="0.2" class="jarallax">
    <img class="jarallax-img" src="<background_image_url_here>" alt="">
    Your content here...
</div>

B. JavaScript way

jarallax(document.querySelectorAll('.jarallax'), {
    speed: 0.2
});

C. jQuery way

$('.jarallax').jarallax({
    speed: 0.2
});

Background Video Usage Examples

<!-- Background YouTube Parallax -->
<div class="jarallax" data-jarallax-video="https://www.youtube.com/watch?v=ab0TSkLe-E0">
    Your content here...
</div>

<!-- Background Vimeo Parallax -->
<div class="jarallax" data-jarallax-video="https://vimeo.com/110138539">
    Your content here...
</div>

<!-- Background Local Video Parallax -->
<div class="jarallax" data-jarallax-video="mp4:./video/local-video.mp4,webm:./video/local-video.webm,ogv:./video/local-video.ogv">
    Your content here...
</div>

Note: for local videos required only 1 video type, not necessary use all mp4, webm and ogv. This need only for maximum compatibility with all browsers.

Any Element Prallax Usage Examples

<!-- Element will be parallaxed on inverted 140 pixels from the screen center -->
<div data-jarallax-element="-140">
    Your content here...
</div>

<!-- Element will be parallaxed on 250 pixels from the screen center -->
<div data-jarallax-element="250">
    Your content here...
</div>

Note: this is more like experimental feature, so the behavior could be changed in the future releases.

Options

Options can be passed in data attributes or in object when you initialize jarallax from script.

nametypedefaultdescription
typestringscrollscroll, scale, opacity, scroll-opacity, scale-opacity.
speedfloat0.5Parallax effect speed. Provide numbers from -1.0 to 2.0.
imgSrcpathnullImage url. By default used image from background.
imgElementdom / selector.jarallax-imgImage tag that will be used as background.
imgSizestringcoverImage size. If you use <img> tag for background, you should add object-fit values, else use background-size values.
imgPositionstring50% 50%Image position. If you use <img> tag for background, you should add object-position values, else use background-position values.
imgRepeatstringno-repeatImage repeat. Supported only background-position values.
keepImgbooleanfalseKepp <img> tag in it's default place after Jarallax inited.
elementInViewportdomnullUse custom DOM / jQuery element to check if parallax block in viewport. More info here - Issue 13.
zIndexnumber-100z-index of parallax container.
noAndroidbooleanfalseDisable parallax on Android devices.
noIosbooleanfalseDisable parallax on iOs devices.

Options For Video (+ supported all default options)

Required jarallax/jarallax-video.js file.

nametypedefaultdescription
videoSrcstringnullYou can use Youtube, Vimeo or local videos. Also you can use data attribute data-jarallax-video.
videoStartTimefloat0Start time in seconds when video will be started (this value will be applied also after loop).
videoEndTimefloat0End time in seconds when video will be ended.
videoVolumefloat0Video volume from 0 to 100.
videoPlayOnlyVisiblebooleantruePlay video only when it is visible on the screen.

Options For Element Parallax

Required jarallax/jarallax-element.js file.

nametypedefaultdescription
typestringelementWill only work with element value.
speedfloat0Parallax distance in pixels. Supported any value. Also you can use data attribute data-jarallax-element.

Events

Evenets used the same way as Options.

namedescription
onScrollCalled when parallax working. Use first argument with calculations. More info see below.
onInitCalled after init end.
onDestroyCalled after destroy.
onCoverImageCalled after cover image.

onScroll event

jarallax(document.querySelectorAll('.jarallax'), {
    onScroll: function(calculations) {
        console.log(calculations);
    }
});

Console Result:

{
    // parallax section client rect (top, left, width, height)
    rect            : object,

    // see image below for more info
    beforeTop       : float,
    beforeTopEnd    : float,
    afterTop        : float,
    beforeBottom    : float,
    beforeBottomEnd : float,
    afterBottom     : float,

    // percent of visible part of section (from 0 to 1)
    visiblePercent  : float,

    // percent of block position relative to center of viewport from -1 to 1
    fromViewportCenter: float
}

Calculations example: On Scroll Calculations

Methods

nameresultdescription
destroy-Destroy Jarallax and set block as it was before plugin init.
isVisiblebooleanCheck if parallax block is in viewport.
onResize-Fit image and clip parallax container. Called on window resize and load.
onScroll-Calculate parallax image position. Called on window scroll.

Call methods example

A. JavaScript way

jarallax(document.querySelectorAll('.jarallax'), 'destroy');

B. jQuery way

$('.jarallax').jarallax('destroy');

No conflict

If you already have global jarallax variable or jQuery.fn.jarallax, you can rename plugin.

A. JavaScript way

var newJarallax = jarallax.noConflict();

B. jQuery way

jQuery.fn.newJarallax = jQuery.fn.jarallax.noConflict();

Real Usage Examples

Credits

Images https://unsplash.com/ Local Video https://videos.pexels.com/

License

Copyright (c) 2017 nK Licensed under the WTFPL license.

Keywords

FAQs

Package last updated on 30 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc