Skip to content

Commit 9611068

Browse files
committed
Fix animation resuming when paused manually then canvas back in view if isPausedWhenNotInView=true
1 parent 58da636 commit 9611068

File tree

7 files changed

+24
-16
lines changed

7 files changed

+24
-16
lines changed

dist/granim.js

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! Granim v1.0.4 - https://sarcadass.github.io/granim.js */
1+
/*! Granim v1.0.5 - https://sarcadass.github.io/granim.js */
22
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
33
'use strict';
44

@@ -397,7 +397,9 @@ module.exports = function() {
397397
},{}],13:[function(require,module,exports){
398398
'use strict';
399399

400-
module.exports = function() {
400+
module.exports = function(state) {
401+
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView';
402+
if (!isPausedBecauseNotInView) this.isPaused = true;
401403
cancelAnimationFrame(this.animation);
402404
};
403405

@@ -425,12 +427,12 @@ module.exports = function() {
425427
if (isNotInView) {
426428
if (!_this.isPaused && !_this.isPausedBecauseNotInView) {
427429
_this.isPausedBecauseNotInView = true;
428-
_this.pause();
430+
_this.pause('isPausedBecauseNotInView');
429431
}
430432
} else {
431-
if (_this.isPausedBecauseNotInView || init) {
433+
if (!_this.isPaused || init === true) {
432434
_this.isPausedBecauseNotInView = false;
433-
_this.play();
435+
_this.play('isPausedBecauseNotInView');
434436
}
435437
}
436438
}, 300);
@@ -440,7 +442,9 @@ module.exports = function() {
440442
},{}],15:[function(require,module,exports){
441443
'use strict';
442444

443-
module.exports = function() {
445+
module.exports = function(state) {
446+
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView';
447+
if (!isPausedBecauseNotInView) this.isPaused = false;
444448
this.animation = requestAnimationFrame(this.animateColors.bind(this));
445449
};
446450

dist/granim.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/assets/js/vendor/granim.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/pause.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3-
module.exports = function() {
3+
module.exports = function(state) {
4+
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView';
5+
if (!isPausedBecauseNotInView) this.isPaused = true;
46
cancelAnimationFrame(this.animation);
57
};

lib/pauseWhenNotInView.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ module.exports = function() {
2121
if (isNotInView) {
2222
if (!_this.isPaused && !_this.isPausedBecauseNotInView) {
2323
_this.isPausedBecauseNotInView = true;
24-
_this.pause();
24+
_this.pause('isPausedBecauseNotInView');
2525
}
2626
} else {
27-
if (_this.isPausedBecauseNotInView || init) {
27+
if (!_this.isPaused || init === true) {
2828
_this.isPausedBecauseNotInView = false;
29-
_this.play();
29+
_this.play('isPausedBecauseNotInView');
3030
}
3131
}
3232
}, 300);

lib/play.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3-
module.exports = function() {
3+
module.exports = function(state) {
4+
var isPausedBecauseNotInView = state === 'isPausedBecauseNotInView';
5+
if (!isPausedBecauseNotInView) this.isPaused = false;
46
this.animation = requestAnimationFrame(this.animateColors.bind(this));
57
};

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "granim",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Create fluid and interactive gradients animations with this small js library.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)