Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion demo/snowf.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@
<button id="noWindBtn" onclick="setWind(0)" class="active">no wind</button>
<button id="EastWindBtn" onclick="setWind(3)">wind -&gt;</button>
</div>

<div class="btn-group">
<button id="playBtn" onclick="play()" class="active">Start</button>
<button id="pauseBtn" onclick="pause()">Stop</button>
</div>

<script src="../snowf.min.js"></script>
<script>

Expand All @@ -82,6 +86,22 @@
snowflakes.speed(opt);
}

//Make the snow stop falling. Falling snow will keep falling until it reaches the end.
function pause() {
snowflakes.pause();
document.getElementsByClassName('active')[2].className = '';
var evt = window.event || arguments.callee.caller.arguments[0];
evt.target.className = 'active';
}

//Make the snow start falling again.
function play() {
snowflakes.play();
document.getElementsByClassName('active')[2].className = '';
var evt = window.event || arguments.callee.caller.arguments[0];
evt.target.className = 'active';
}

// change wind level
function setWind(wind) {
document.getElementsByClassName('active')[1].className = '';
Expand Down
16 changes: 14 additions & 2 deletions snowf.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
var config = {};
var requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) { window.setTimeout(callback, 1000 / 60);};
var cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame || window.mozCancelAnimationFrame || window.msCancelAnimationFrame || function(callback) { window.clearTimeout(callback);};
var paused = false;

// default options
var defaults = {
Expand Down Expand Up @@ -112,8 +113,8 @@
flake.velX = Math.abs(flake.velX) < Math.abs(o.wind) ? flake.velX + o.wind / 20 : o.wind;
flake.y = flake.y + flake.velY * 0.5;
flake.x = flake.x + (o.swing ? 0.4 * Math.cos(flake.swing += 0.03) * flake.opacity * o.swing : 0) + flake.velX * 0.5;
if (flake.x > self.width + flake.r || flake.x < -flake.r || flake.y > self.height + flake.r || flake.y < -flake.r) {
_reset(flake);
if (!paused && (flake.x > self.width + flake.r || flake.x < -flake.r || flake.y > self.height + flake.r || flake.y < -flake.r)) {
_reset(flake);
}
}
self.animationFrame = requestAnimationFrame(_snow);
Expand Down Expand Up @@ -145,6 +146,17 @@
return this;
};

/**
* Stop snowflakes.
* @public
*/
Snowf.prototype.pause = function() {
paused = true;
};

Snowf.prototype.play = function() {
paused = false;
};
/**
* Set options and reset snowflakes.
* @public
Expand Down
2 changes: 1 addition & 1 deletion snowf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.