A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pixelcog/parallax.js/tree/v2.0.0-alpha below:

GitHub - pixelcog/parallax.js at v2.0.0-alpha

Warning: This branch is still in alpha and should not be used on production servers! It should, however, be stable enough already, so please feel free to check it out and let us know if you find some issues!

please clone or download the repository and check the dist folder for the necessary files.

NPM, Yarn, Bower as well as CDN support will be added for the release version.

If not disabled, the library automatically calls itself on all elements with a data-parallax attribute with the default parameters like so:

// this is called automatically:
if(Parallax.AUTOINIT) {
  $('[data-parallax]').parallax();
}
// if you don't previously set  
Parallax.AUTOINIT = false;

####Init Basically, you can call the parallax() function on any jquery selector. The selected elements either need to have a data-src attribute or a child element which is matched by the sliderSelector query (see options).

The default values, which are used for .parallax() (and merged with an optional options parameter), look as follows:

Parallax.DEFAULTS = {
  src: null,
  speed: .2,
  bleed: 0,
  zIndex: -100,
  posX: 'center',
  posY: 'center',
  overScrollFix: false,
  excludeAgents: /(iPod|iPhone|iPad|Android)/,
  aspectRatio: null,
  // jquery selectors
  sliderSelector: '>.parallax-slider',
  mirrorSelector: 'body',
  // callback functions:
  afterRefresh: null,
  afterRender: null,
  afterSetup: null,
  afterDestroy: null,
};

These defaults can be changed easily, e.g.:

Parallax.DEFAULTS.speed = -.2;
Parallax.DEFAULTS.afterRefresh = (instance) => { doSomethingWith(instance); };

Data Attributes can be used for quick an easy setup when no complex solutions are required.

<div class="some-class" data-src="some-img.jpg" data-pos-x="left" data-parallax>

All options can be used as attributes. "Kebab-case" and the data- prefix have to be used instead of CamelCase in the JavaScript options. (e.g. aspectRatio gets data-aspect-ratio)

Important: Please note, that the <div> above will be used as the so called parallax-window and needs to have a minimum-height and transparency.

Adding the following CSS or similar will be necessary:

.some-class {
  min-height: 50vh;
  background: transparent;
}

If you don't use autoinit or need more control over the instances, you can manually initialize parallax.js and pass options via an options object

$('.any-selector-you-like-but-this-is-called-window').parallax({
  speed: .3,
  afterRender: doSomething,
});

Each instance can be destroyed by calling .parallax('destroy') on the element (window).

$('.any-selector-you-like-but-this-is-called-window').parallax('destroy');

The following options can be used:

Name Attribute Default Description src data-src null path to an image speed data-speed 0.2 float which is used to calculate the speed.
Values from -1 to 1 are most useful. bleed data-bleed 0 the number of pixels used as "bleed" above and below the slide.
This causes an overlap and can be used to fix scrolling issues on some browsers.
A value of 50 is sufficient in most cases. zIndex data-z-index -100 the z-index of the parallax mirror posX data-pos-x 'center' number in px, 'left' or 'right' is used to calculate the x-offset.
Only effective when the aspect ratio of the content smaller than the aspect ratio of the window.
i.e. the content height is higher in relation to the window posY data-pos-y 'center' number in px, 'top' or 'bottom' is used to calculate the y-offset.
Only effective when the aspect ratio of the content larger than the aspect ratio of the window.
i.e. the content width is wider relation to the window overScrollFix data-over-scroll-fix false If true, will freeze the parallax effect when "over scrolling" in browsers like Safari to prevent unexpected gaps caused by negative scroll positions. excludeAgents data-exclude-agents /(iPod|iPhone|
iPad|Android)/ regular expression, when matched with the user agent, the parallax effect is not applied. The image is set as background when data-src is used. aspectRatio data-aspect-ratio null (automatic) the aspect ratio which should be utilized for the content. sliderSelector data-slider-selector '>.parallax-slider' the jquery selector for the slider $currentElement.find(options.sliderSelector); mirrorSelector data-mirror-selector 'body' the jquery selector for the container where the mirror is prepended $mirror.prependTo($(options.mirrorSelector)); afterRefresh data-after-refresh null callback which is called after refresh afterRender data-after-render null callback which is called after render afterSetup data-after-setup null callback which is called after setup afterDestroy data-after-destroy null callback which is called after destroy

v2.x has been redesigned from ground up to improve maintainability, compatibility and performance.

The most important changes:

<div class="my-parallax-window">
  <div class="my-parallax-slider">
    <img src="some-image.jpg"/>
    <p>This content and the image will move when scrolling</p>
  </div>
  <div class="some-optional-fixed-content">
    <p>This content will stay in place</p>
  </div>
</div>
$('.my-parallax-window').parallax({
  speed: -.2,
  sliderSelector: '>.my-parallax-slider',
})

Most important changes include the following:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4