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
efe992b4
Commit
efe992b4
authored
3 years ago
by
Dj
Browse files
Options
Downloads
Patches
Plain Diff
Fix: on window resize
parent
4f2dd94e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/parallax-css-testpage/particles.js
+56
-20
56 additions, 20 deletions
src/parallax-css-testpage/particles.js
src/parallax-css-testpage/template.html
+3
-2
3 additions, 2 deletions
src/parallax-css-testpage/template.html
with
59 additions
and
22 deletions
src/parallax-css-testpage/particles.js
+
56
−
20
View file @
efe992b4
...
@@ -14,7 +14,7 @@ const Static = true
...
@@ -14,7 +14,7 @@ const Static = true
function
randomValue
(
min
,
max
)
{
function
randomValue
(
min
,
max
)
{
const
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
(
value
===
0
||
value
===
1
)
?
randomValue
(
min
,
max
)
?
randomValue
(
min
,
max
)
...
@@ -22,12 +22,12 @@ function randomValue(min, max) {
...
@@ -22,12 +22,12 @@ function randomValue(min, max) {
}
}
function
getNodeYOffset
(
node
)
{
function
getNodeYOffset
(
node
)
{
const
dimensions
=
node
.
getBoundingClientRect
()
var
dimensions
=
node
.
getBoundingClientRect
()
return
(
dimensions
)
?
dimensions
.
y
:
0
return
(
dimensions
)
?
dimensions
.
y
:
0
}
}
function
getNodeHeight
(
node
)
{
function
getNodeHeight
(
node
)
{
const
dimensions
=
node
.
getBoundingClientRect
()
var
dimensions
=
node
.
getBoundingClientRect
()
return
(
dimensions
)
?
dimensions
.
height
:
window
.
innerHeight
return
(
dimensions
)
?
dimensions
.
height
:
window
.
innerHeight
}
}
...
@@ -67,8 +67,8 @@ function Particle({ position, direction, size, color }) {
...
@@ -67,8 +67,8 @@ function Particle({ position, direction, size, color }) {
function
Update
(
scene
,
particle
)
{
function
Update
(
scene
,
particle
)
{
// Cache object access
// Cache object access
const
width
=
scene
.
width
var
width
=
scene
.
width
const
height
=
scene
.
height
var
height
=
scene
.
height
// Animate the pulse effect of the particle
// Animate the pulse effect of the particle
//
//
...
@@ -268,23 +268,59 @@ function CreateParticles(scene, {
...
@@ -268,23 +268,59 @@ function CreateParticles(scene, {
function
Particles
(
configs
)
{
function
Particles
(
configs
)
{
function
doRenderParticles
(
rendererList
)
{
function
animate
(
rendererList
)
{
if
(
isRunning
)
{
requestAnimationFrame
(
function
()
{
requestAnimationFrame
(
function
()
{
doRenderParticles
(
animate
(
rendererList
.
map
(
function
doRender
(
render
)
{
rendererList
.
map
(
function
doRender
(
render
)
{
return
render
()
return
render
()
})
})
)
)
})
})
}
}
}
return
function
()
{
function
init
()
{
doRenderParticles
(
return
configs
.
map
(
function
(
particleConfig
)
{
configs
.
map
(
function
(
particleConfig
)
{
var
scene
=
CreateScene
(
particleConfig
.
scene
)
var
scene
=
CreateScene
(
particleConfig
.
scene
)
var
particles
=
CreateParticles
(
scene
,
particleConfig
.
particles
)
var
particles
=
CreateParticles
(
scene
,
particleConfig
.
particles
)
return
Animate
(
scene
,
particles
)
return
Animate
(
scene
,
particles
)
})
})
)
}
var
particles
=
[]
var
isRunning
=
false
var
throttled
=
false
var
delay
=
250
return
{
init
:
function
()
{
particles
=
init
()
},
run
:
function
()
{
if
(
particles
.
length
===
0
)
{
particles
=
init
()
}
isRunning
=
true
animate
(
particles
)
},
stop
:
function
()
{
isRunning
=
false
},
onScreenSizeChange
:
function
()
{
isRunning
=
false
if
(
!
throttled
)
{
throttled
=
true
setTimeout
(
function
()
{
particles
=
init
()
isRunning
=
true
animate
(
particles
)
throttled
=
false
},
delay
)
}
}
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/parallax-css-testpage/template.html
+
3
−
2
View file @
efe992b4
...
@@ -121,11 +121,12 @@
...
@@ -121,11 +121,12 @@
}
}
}
}
var
animat
e
=
Particles
([
var
animat
ion
=
Particles
([
fgParticleConfig
,
fgParticleConfig
,
bgParticleConfig
,
bgParticleConfig
,
])
])
animate
()
animation
.
run
()
window
.
addEventListener
(
'
resize
'
,
animation
.
onScreenSizeChange
)
</script>
</script>
</body>
</body>
...
...
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