Hello, I’m working on a JavaScript project that visualizes the amount of time a user has lived in weeks. I have a grid of cells representing each week, where the cells that the user has already lived are filled with black. I would like to overlay a gradient on top of the filled cells for design purposes.
I’m wondering if anyone has any suggestions on how I could achieve this effect? Any help or guidance would be greatly appreciated!
Thanks for your reply. What I’m looking to do is not to have each ‘owl’ class cell filled in with a gradient, but instead have the entire body of ‘owl’ cells make up a dynamic gradient.
I got close but no cigar as there are problems in rubbing out some odd bits and pieces.
I thought it might be possible using a css mask to reveal the background but there is the same issue as my method above of just revealing the bits you want to see.
Could you fake the gradient effect by giving each square a solid fill which alters gradually from one to the next?
Though that would probably revert to using JS to add the style attributes.
The compromise is that it uses a fixed background to achieve the effect so effectively the gradients length is the viewport height and width.
It’s probably not noticeable but if you scroll the page then a slightly different part of the gradient is seen in the squares. (It’s often used like this for parallax effects)
One thing I should have mentioned is that mobile devices don’t like background attachment fixed combined with cover and will result in a gradient that is the length of the document not the viewport. It just means that the gradient will be less noticeable on mobile but will still work.
A couple of other notes:
The animation doesnt restart from blank if you change the date.
Consequently of above: if you put an old date in, and then a newer one, the wrong number of boxes are lit up.
Consider making the style (borrder, borderRadius) changes in your javascript part of the “owl” class, rather than the javascript. Much cleaner to just add/remove a class…