Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stop autoclose if user mouseovers the toast #43

Open
arashdalir opened this issue Feb 13, 2023 · 0 comments
Open

stop autoclose if user mouseovers the toast #43

arashdalir opened this issue Feb 13, 2023 · 0 comments

Comments

@arashdalir
Copy link

arashdalir commented Feb 13, 2023

we are using the toasts as information boxes on our website and need to keep them open if the user hovers over the toast message. to achieve this, I turned autoclose off (autoclose: false) and added the following code.

but this could also be achieved if a flag like stopAutoCloseOnMouseover would be implemented, which would trigger this behavior.

var notify = new Notify(settings);
    notify.autoclose_mo = true;

    notify.autoCloseMo = function (){
      if(notify.autoclose_mo)
      {
        notify.autoCloseMoTimeout = setTimeout(
          function (){
            notify.close();
          },
          notify.autotimeout + notify.speed
        );
        notify.wrapper.classList.add('notify-autoclose');
        notify.wrapper.style.setProperty('--timeout', notify.autotimeout+notify.speed);
      }
    }

    $(notify.wrapper)
      .on("mouseover", function (){
        if(notify.autoCloseMoTimeout)
        {
          clearTimeout(notify.autoCloseMoTimeout);
          notify.wrapper.classList.add('paused-animation');
        }
      })
      .on("mouseout", function (){
        notify.wrapper.classList.remove('notify-autoclose');
        notify.wrapper.classList.remove('paused-animation');
        void notify.wrapper.offsetWidth;
        notify.autoCloseMo();
      });
    notify.autoCloseMo();

also, following css is important for the timeout bar to stop moving during the mousever:

.paused-animation,
.paused-animation::before{
	animation-play-state: paused !important;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant