diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..7a9dfa0 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/demos/js/jquery.toast.js b/demos/js/jquery.toast.js index 77cdf45..8f29af2 100644 --- a/demos/js/jquery.toast.js +++ b/demos/js/jquery.toast.js @@ -279,9 +279,7 @@ if ( typeof Object.create !== 'function' ) { if (this.canAutoHide()) { var that = this; - - window.setTimeout(function(){ - + var hideFunction = function (){ if ( that.options.showHideTransition.toLowerCase() === 'fade' ) { that._toastEl.trigger('beforeHide'); that._toastEl.fadeOut(function () { @@ -298,8 +296,15 @@ if ( typeof Object.create !== 'function' ) { that._toastEl.trigger('afterHidden'); }); } + } + + var timer = window.setTimeout(hideFunction, this.options.hideAfter); - }, this.options.hideAfter); + that._toastEl.hover(() => { + clearTimeout(timer); + }, () => { + timer = window.setTimeout(hideFunction, this.options.hideAfter); + }) }; }, diff --git a/src/jquery.toast.js b/src/jquery.toast.js index 1563986..5ae90bc 100644 --- a/src/jquery.toast.js +++ b/src/jquery.toast.js @@ -285,9 +285,7 @@ if ( typeof Object.create !== 'function' ) { if (this.canAutoHide()) { var that = this; - - window.setTimeout(function(){ - + var hideFunction = function (){ if ( that.options.showHideTransition.toLowerCase() === 'fade' ) { that._toastEl.trigger('beforeHide'); that._toastEl.fadeOut(function () { @@ -304,8 +302,15 @@ if ( typeof Object.create !== 'function' ) { that._toastEl.trigger('afterHidden'); }); } + } + + var timer = window.setTimeout(hideFunction, this.options.hideAfter); - }, this.options.hideAfter); + that._toastEl.hover(() => { + clearTimeout(timer); + }, () => { + timer = window.setTimeout(hideFunction, this.options.hideAfter); + }) }; },