Skip to content

Commit

Permalink
🔥 remove breakpoint setting
Browse files Browse the repository at this point in the history
  • Loading branch information
signorato.g@pg.com committed Dec 6, 2019
1 parent 76dfa35 commit d65531d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 41 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ scale | int | 1.3 | need to be above 1.0
overflow | boolean | false |
delay | int | 0.4 | the delay is in second
transition | string | false | any CSS transition
breakpoint | int | false | the breakpoint is in pixel

You can apply these settings with the following JS code:

Expand Down Expand Up @@ -102,9 +101,6 @@ When a delay is set, the translation of the image will slightly continue when th
### transition - *string*
The transition works closely with the delay setting. The transition will add any CSS effect to the delay setting.

### breakpoint - *int*
The minimum breakpoint from where simpleParallax should be initialized and to where simpleParallax should be destroyed.

## Methods
Destroy a simpleParallax instance:

Expand Down
50 changes: 26 additions & 24 deletions dist/simpleParallax.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* simpleParallax - simpleParallax is a simple JavaScript library that gives your website parallax animations on any images,
* @date: 02-09-2019 19:12:2,
* @date: 06-12-2019 13:53:55,
* @version: 5.1.0,
* @link: https://simpleparallax.com/
*/
Expand Down Expand Up @@ -251,6 +251,8 @@ function () {
parallax_createClass(ParallaxInstance, [{
key: "init",
value: function init() {
var _this = this;

// for some reason, <picture> are init an infinite time on windows OS
if (this.isInit) return; // check if element has not been already initialized with simpleParallax

Expand All @@ -260,18 +262,27 @@ function () {
// if overflow option is set to false
// wrap the element into a div to apply overflow
this.wrapElement(this.element);
} // apply the default style on the image
} // apply the transform style on the image


this.setStyle(); // get the current element offset
this.setTransformCSS(); // get the current element offset

this.getElementOffset(); // init the Intesection Observer

this.intersectionObserver(); // get its translated value

this.getTranslateValue(); // apply its translation even if not visible for the first init

this.animate(); // for some reason, <picture> are init an infinite time on windows OS
this.animate(); // if a delay has been set

if (this.settings.delay > 0) {
// apply a timeout to avoid buggy effect
setTimeout(function () {
// apply the transition style on the image
_this.setTransitionCSS();
}, 10);
} // for some reason, <picture> are init an infinite time on windows OS


this.isInit = true;
} // if overflow option is set to false
Expand Down Expand Up @@ -300,22 +311,23 @@ function () {
} // apply default style on element

}, {
key: "setStyle",
value: function setStyle() {
key: "setTransformCSS",
value: function setTransformCSS() {
if (this.settings.overflow === false) {
// if overflow option is set to false
// add scale style so the image can be translated without getting out of its container
this.element.style[helpers_cssTransform] = "scale(".concat(this.settings.scale, ")");
}

if (this.settings.delay > 0) {
// if delay option is set to true
// add transition option
this.element.style.transition = "transform ".concat(this.settings.delay, "s ").concat(this.settings.transition);
} // add will-change CSS property to improve perfomance


this.element.style.willChange = 'transform';
} // apply the transition effet

}, {
key: "setTransitionCSS",
value: function setTransitionCSS() {
// add transition option
this.element.style.transition = "transform ".concat(this.settings.delay, "s ").concat(this.settings.transition);
} // remove style of the element

}, {
Expand Down Expand Up @@ -496,15 +508,9 @@ function () {
orientation: 'up',
scale: 1.3,
overflow: false,
transition: 'cubic-bezier(0,0,0,1)',
breakpoint: false
transition: 'cubic-bezier(0,0,0,1)'
};
this.settings = Object.assign(this.defaults, options); // check if breakpoint is set and superior to user browser width

if (this.settings.breakpoint && document.documentElement.clientWidth <= this.settings.breakpoint) {
return;
} // check if the browser handle the Intersection Observer API

this.settings = Object.assign(this.defaults, options); // check if the browser handle the Intersection Observer API

if (!('IntersectionObserver' in window)) intersectionObserverAvailable = false;
this.lastPosition = -1;
Expand Down Expand Up @@ -548,10 +554,6 @@ function () {
// re-get all the viewport positions
simpleParallax_viewport.setViewportAll();

if (this.settings.breakpoint && document.documentElement.clientWidth <= this.settings.breakpoint) {
this.destroy();
}

for (var i = instancesLength - 1; i >= 0; i--) {
// re-get the current element offset
instances[i].getElementOffset(); // re-get the range if the current element
Expand Down
Loading

0 comments on commit d65531d

Please sign in to comment.