-
Notifications
You must be signed in to change notification settings - Fork 5
Preload image by adding Poppy to DOM on init #2
base: master
Are you sure you want to change the base?
Conversation
src/Poppy.js
Outdated
if (this.state.position === "topLeft" || this.state.position === "topRight") { | ||
this.element.style.transform = 'translateY(10%)'; | ||
} else if (this.state.position === "bottomLeft" || this.state.position === "bottomRight") { | ||
container.style.transform = 'translateY(0)'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transform should be applied to this.element
instead of container
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
I'm not sold on the idea of initializing it on DOM before actually displaying it. Although this enables to have a transition, this would add unnecessary DOM elements without even displaying it. Also, there is possibility that we wouldn't clean up these elements from the DOM if show/hide isn't called at all. And, for a use-case of such a pop-in message box, I don't think we would show it on page load. It would be show on state changes, new notifications, messages post page loading or on scroll. Let's create an issue and get more opinions on the same to proceed. |
Here's a proof-of-concept for preloading the image by inserting the Poppy element upon instantiation.
show()
method toinit()
which will run upon eachnew Poppy()
.show()
method now un-hides the Poppy element with a CSS transition animation.close()
method animates the Poppy element out of view, then destroys the element.I updated example in
index.html
that follows the new methods outlined above, so please take a look.I don't know if this is the best way to implement it, so please give your feedback! Thanks!