Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
7d28b015
Commit
7d28b015
authored
Dec 26, 2021
by
Dj
Browse files
Options
Downloads
Patches
Plain Diff
Add: Particle scaling depending on content size
parent
09f122e8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parallax-css-testpage/particles.js
+16
-3
16 additions, 3 deletions
src/parallax-css-testpage/particles.js
src/parallax-css-testpage/template.html
+3
-3
3 additions, 3 deletions
src/parallax-css-testpage/template.html
with
19 additions
and
6 deletions
src/parallax-css-testpage/particles.js
+
16
−
3
View file @
7d28b015
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
function
randomValue
(
min
,
max
)
{
function
randomValue
(
min
,
max
)
{
var
value
=
(
Math
.
random
()
*
(
+
max
-
+
min
)
+
+
min
)
var
value
=
(
Math
.
random
()
*
(
+
max
-
+
min
)
+
+
min
)
// Prevent values that can be possible boring
// Prevent values that can be possible boring
return
(
value
===
0
||
value
===
1
)
return
(
min
!==
0
&&
max
!==
0
&&
(
value
===
0
||
value
===
1
)
)
?
randomValue
(
min
,
max
)
?
randomValue
(
min
,
max
)
:
value
:
value
}
}
...
@@ -31,6 +31,17 @@ function getNodeHeight(node) {
...
@@ -31,6 +31,17 @@ function getNodeHeight(node) {
return
(
dimensions
)
?
dimensions
.
height
:
window
.
innerHeight
return
(
dimensions
)
?
dimensions
.
height
:
window
.
innerHeight
}
}
function
calcParticleCount
(
scene
,
particleDensity
)
{
var
referenceArea
=
100
*
100
// 100px * 100px => px^2
var
sceneVolume
=
scene
.
width
*
scene
.
height
var
scale
=
100
var
particleFactor
=
(
sceneVolume
/
referenceArea
)
/
scale
var
particleCount
=
Math
.
abs
(
Math
.
trunc
(
particleFactor
*
particleDensity
))
return
particleCount
||
0
}
//
//
// Data
// Data
...
@@ -233,14 +244,16 @@ function CreateScene({ canvasId, contentId, depth, fps }) {
...
@@ -233,14 +244,16 @@ function CreateScene({ canvasId, contentId, depth, fps }) {
function
CreateParticles
(
scene
,
{
function
CreateParticles
(
scene
,
{
amount
,
density
,
color
,
color
,
size
,
size
,
speed
,
speed
,
lifespan
,
lifespan
,
})
{
})
{
return
Array
.
from
(
return
Array
.
from
(
{
length
:
amount
},
{
length
:
calcParticleCount
(
scene
,
density
)
},
function
createParticle
()
{
function
createParticle
()
{
return
Particle
({
return
Particle
({
position
:
position
:
...
...
This diff is collapsed.
Click to expand it.
src/parallax-css-testpage/template.html
+
3
−
3
View file @
7d28b015
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
<div
class=
"static full-bg bg-image"
></div>
<div
class=
"static full-bg bg-image"
></div>
<div
class=
"static full-bg vcr-overlay"
></div>
<div
class=
"static full-bg vcr-overlay"
></div>
<div
class=
"static full-bg grid"
></div>
<div
class=
"static full-bg grid"
></div>
<canvas
id=
"debug-particles"
class=
"static full-bg particles"
></canvas>
<canvas
id=
"bg-particles"
class=
"static full-bg particles"
></canvas>
<canvas
id=
"bg-particles"
class=
"static full-bg particles"
></canvas>
<div
class=
"static full-bg vignette"
></div>
<div
class=
"static full-bg vignette"
></div>
<canvas
id=
"fg-particles"
class=
"static full-bg particles"
></canvas>
<canvas
id=
"fg-particles"
class=
"static full-bg particles"
></canvas>
...
@@ -94,7 +95,7 @@
...
@@ -94,7 +95,7 @@
depth
:
2.5
,
depth
:
2.5
,
},
},
particles
:
{
particles
:
{
amount
:
50
,
density
:
15
,
color
:
'
white
'
,
color
:
'
white
'
,
size
:
40
,
size
:
40
,
speed
:
0.5
,
speed
:
0.5
,
...
@@ -113,14 +114,13 @@
...
@@ -113,14 +114,13 @@
depth
:
0.08
,
depth
:
0.08
,
},
},
particles
:
{
particles
:
{
amount
:
1
5
0
,
density
:
1
0
0
,
color
:
'
white
'
,
color
:
'
white
'
,
size
:
7
,
size
:
7
,
speed
:
0.2
,
speed
:
0.2
,
lifespan
:
8000
// in milliseconds
lifespan
:
8000
// in milliseconds
}
}
}
}
var
animation
=
Particles
([
var
animation
=
Particles
([
fgParticleConfig
,
fgParticleConfig
,
bgParticleConfig
,
bgParticleConfig
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment