Alex-D / Cookies-EU-banner

1kb vanilla JS script which manages cookies consent banner display like asked by GDPR
http://alex-d.github.io/Cookies-EU-banner/
MIT License
441 stars 57 forks source link

Animating out // wait-remove with "before-remove" class #53

Closed sebastian-marinescu closed 4 years ago

sebastian-marinescu commented 4 years ago

Hi @Alex-D, first of all thanks a lot for this great, simple and beautiful script.

I'd like to animate the banner in, and out - in both cases: on accept & on reject. Right now this is not possible, as their is no indication of the upcoming DOM-removal.

I'm suggesting setting a class in the removeBanner method, like this:

    removeBanner: function(wait) {
      var banner = document.getElementById("cookies-eu-banner");
      banner.classList.add("before-remove");
      setTimeout(function() {
        if (banner && banner.parentNode) {
          banner.parentNode.removeChild(banner);
        }
      }, wait);
    }

Here is a demo of how I'm going to use it: https://codepen.io/sebastian-marinescu/pen/MWwGLwY?editors=0010

If you are okay with this, I'm preparing a PR.