fix: snowflakes falling below window viewport
This commit is contained in:
parent
5f713d33d2
commit
225049b510
1 changed files with 41 additions and 40 deletions
|
@ -7,7 +7,6 @@
|
||||||
// - Made snowflakes randomly rotate slowly either right or left
|
// - Made snowflakes randomly rotate slowly either right or left
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Amount of Snowflakes
|
// Amount of Snowflakes
|
||||||
var snowMax = 80;
|
var snowMax = 80;
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@ function randomise(range) {
|
||||||
|
|
||||||
function initSnow() {
|
function initSnow() {
|
||||||
var snowSize = snowMaxSize - snowMinSize;
|
var snowSize = snowMaxSize - snowMinSize;
|
||||||
marginBottom = window.screen.height - 5;
|
marginBottom = Math.max(document.body.scrollHeight, window.innerHeight) - 5;
|
||||||
marginRight = document.body.clientWidth - 15;
|
marginRight = document.body.clientWidth - 15;
|
||||||
|
|
||||||
for (i = 0; i <= snowMax; i++) {
|
for (i = 0; i <= snowMax; i++) {
|
||||||
|
@ -82,7 +81,7 @@ function initSnow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function resize() {
|
function resize() {
|
||||||
marginBottom = window.screen.height - 5;
|
marginBottom = Math.max(document.body.scrollHeight, window.innerHeight) - 5;
|
||||||
marginRight = document.body.clientWidth - 15;
|
marginRight = document.body.clientWidth - 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +92,7 @@ function moveSnow() {
|
||||||
snow[i].style.left = snow[i].posX + lefr[i] * Math.sin(coords[i]) + "px";
|
snow[i].style.left = snow[i].posX + lefr[i] * Math.sin(coords[i]) + "px";
|
||||||
snow[i].style.top = snow[i].posY + "px";
|
snow[i].style.top = snow[i].posY + "px";
|
||||||
|
|
||||||
|
|
||||||
if (snow[i].posY >= marginBottom - 2 * snow[i].size || parseInt(snow[i].style.left) > (marginRight - 3 * lefr[i])) {
|
if (snow[i].posY >= marginBottom - 2 * snow[i].size || parseInt(snow[i].style.left) > (marginRight - 3 * lefr[i])) {
|
||||||
snow[i].posX = randomise(marginRight - snow[i].size);
|
snow[i].posX = randomise(marginRight - snow[i].size);
|
||||||
snow[i].posY = 0;
|
snow[i].posY = 0;
|
||||||
|
@ -110,3 +110,4 @@ for (i = 0; i <= snowMax; i++) {
|
||||||
|
|
||||||
window.addEventListener('resize', resize);
|
window.addEventListener('resize', resize);
|
||||||
window.addEventListener('load', initSnow);
|
window.addEventListener('load', initSnow);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue