-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from evaristocuesta/animate-stop-0.2.0
Issue #8: Animate and stop functions added
- Loading branch information
Showing
10 changed files
with
143 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,28 @@ | ||
const imagejh = document.getElementById('image-jh'); | ||
const imageay = document.getElementById('image-ay'); | ||
|
||
window.onload = function initialize() { | ||
|
||
pict2pix.animate({ | ||
image: imagejh, | ||
numberOfParticles: 1500, | ||
numberOfParticles: 800, | ||
horizontalSpeed: -1, | ||
verticalSpeed: -1, | ||
particleType: 'straight-particle' | ||
particleType: 'twisted-particle' | ||
}); | ||
} | ||
|
||
const imageay = document.getElementById('image-ay'); | ||
const div2 = document.getElementById('div2'); | ||
|
||
div2.onmouseenter = function over() { | ||
pict2pix.animate({ | ||
image: imageay, | ||
numberOfParticles: 800, | ||
horizontalSpeed: 1, | ||
verticalSpeed: 1, | ||
particleType: 'twisted-particle' | ||
particleType: 'straight-particle' | ||
}); | ||
} | ||
|
||
div2.onmouseleave = function out() { | ||
pict2pix.stop(imageay.id); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
import Pict2Pix from "./pict2pix.js"; | ||
|
||
var pict2PixArray = {}; | ||
|
||
export function animate(config) { | ||
return new Pict2Pix(config); | ||
} | ||
if (!pict2PixArray[config.image.id]) { | ||
pict2PixArray[config.image.id] = {pict2pix: new Pict2Pix(config), running: true}; | ||
} | ||
pict2PixArray[config.image.id].running = true; | ||
pict2PixArray[config.image.id].pict2pix.start(); | ||
} | ||
|
||
export function stop(id) { | ||
pict2PixArray[id].running = false; | ||
pict2PixArray[id].pict2pix.stop(); | ||
} | ||
|
||
function startAll() { | ||
for (var key in pict2PixArray) { | ||
if (pict2PixArray[key].running) { | ||
pict2PixArray[key].pict2pix.start(); | ||
} | ||
} | ||
} | ||
|
||
function stopAll() { | ||
for (var key in pict2PixArray) { | ||
if (pict2PixArray[key].running) { | ||
pict2PixArray[key].pict2pix.stop(); | ||
} | ||
} | ||
} | ||
|
||
function handleVisibilityChange() { | ||
if (document.visibilityState === "hidden") { | ||
stopAll(); | ||
} else { | ||
startAll(); | ||
} | ||
} | ||
|
||
document.addEventListener("visibilitychange", handleVisibilityChange, false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters