+ 3

need help with js loop

i'm trying to make the javascript effects show on multiple divs i'm trying to add class attributes to and use "queryselectorAll & foreach" to loop through the javascript animation so the effects can show on multiple divs but i keep breaking the code please help https://code.sololearn.com/W3OGQSy6Xgjs/?ref=app

5th Apr 2022, 11:37 PM
loop
loop - avatar
14 Respostas
+ 10
At line 520 the parameter, can it be an htmlObject instead of a selector? https://code.sololearn.com/W4C0atqzBzUG
6th Apr 2022, 1:45 AM
ODLNT
ODLNT - avatar
+ 4
Add a different id to each canvas element then pass the canvas id to gradient.initGradient(selector) method and be sure to use let instead of var to initialise gradient. Replace line 709 and 710 with... document.querySelectorAll('.gl-header').forEach(div=>{ let id = div.querySelector('canvas').id let gradient = new Gradient(); gradient.initGradient(`#${id}`) }) https://code.sololearn.com/W4C0atqzBzUG/?ref=app
6th Apr 2022, 12:58 AM
ODLNT
ODLNT - avatar
+ 3
That's always a good thing 😌 I'm glad i was able to help.
6th Apr 2022, 2:27 AM
ODLNT
ODLNT - avatar
+ 2
thanks ODLNT i have already done something like that before but i want to loop through just one class instead of having to write multiple ids since the results are coming from a php / mysql server and i'm not permitted to insert id names into the database
6th Apr 2022, 1:31 AM
loop
loop - avatar
+ 2
well, changing it didn't break anything đŸ˜…đŸ€—, thank you so much
6th Apr 2022, 1:51 AM
loop
loop - avatar
+ 2
loop Trying to understand webgl. I was studying the code and it looked like there is a webgl renderer and debugger inside. So I did a quick google search and found something related to it. the code: https://gist.github.com/osied/2a8afd1fb8e5c62f6c8d14e6e477defb The code is well comented. I think it could be simplified further if the playback controls are omitted. And here is a site that explains how to replicate it. https://kevinhufnagl.com/how-to-stripe-website-gradient-effect/
8th Apr 2022, 1:38 PM
Bob_Li
Bob_Li - avatar
+ 2
thanks bob, kevin's site explains it so well
8th Apr 2022, 6:09 PM
loop
loop - avatar
+ 2
loop Edited the webgl code and minified it. The breakthrough for multi-element assignment is really ODLNT 's work. Without that modification, it was not possible to apply the webgl to multiple canvas element. The javascript code now is just a few lines. But that last line is still a big one.😁 https://code.sololearn.com/WD74Q4Sowl1D/?ref=app
9th Apr 2022, 7:55 AM
Bob_Li
Bob_Li - avatar
+ 2
Bob_Li hehe, talk about over-engineering, on stripe's part
9th Apr 2022, 1:01 PM
loop
loop - avatar
+ 1
loop that is a complicated code for a beautiful background.
7th Apr 2022, 9:12 AM
Bob_Li
Bob_Li - avatar
+ 1
lol
7th Apr 2022, 12:53 PM
loop
loop - avatar
0
Hi
7th Apr 2022, 7:50 AM
Joseph
0
loop I think the code was meant to be used in a web ui, so there were additional code for user interaction. But if we are just using it as a background generator, the unused portions can be edited out. I just opened it in my ide and started commenting out parts to see what was needed and what was not. Then used an online javascript minifier to compress the webgl part. In the process, I started to get a general idea on what the functions do, which proved to be helpful when I started reading about webgl. To learn more about webgl: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Tutorial
9th Apr 2022, 1:19 PM
Bob_Li
Bob_Li - avatar