I always have to search for how to do this or refer back to my previous code whenever I work with fetch. For a while, I've used the solution to thi...
For further actions, you may consider blocking this person and/or reporting abuse
This is largely irrelevant to your post :), but you can replace
with
which I think makes things a little easier to read and won't interfere with any existing classes.
Very nice. Didn't know about that 😀
Getting JavaScript to interact with CSS is a really good way to handle this.
Just for personal preference, I'd probably use the built-in hidden attribute, rather than having a
showclass. I'd also animate as small an area as possible by moving the spinner to a pseudo-class.Great work 🙂
Oh this is good! spinner is gone as the promise is resolved!
You did a common mistake, to not hide the spinner at error, see promise.catch().
I know that error handling is a tabu subject in the JS ecosystem, but we should change this.
Didn’t know about promise.catch. I’ll check it out. Thanks!
At least use ".finally()" to hide spinner at the end of process. Indeed, ".then()" will never called on error and spinner will stay stuck.
Nice I love to have script on my newly develop blog site.
Thanks a lot ! Very clear explanation
Thank you very much bro. It's easier than I thought.
But then, there's a catch. How is it related to the time of loading data. As in, it will always load for 5 seconds irrespective of the actual loading time, isn't it?
ya.he just put it there for demonstration.
Great .Is there a way to change the loading icon animating speed based upon the content fetched uptill now . Should spin fast if content is about to fully download