My client wants an attractive DIV to show up when someone tries to move their mouse up to close the browser tab, and works cross-platform in the latest browsers.
What is the jQuery technique for detecting that particular kind of mouse movement?
My client wants an attractive DIV to show up when someone tries to move their mouse up to close the browser tab, and works cross-platform in the latest browsers.
What is the jQuery technique for detecting that particular kind of mouse movement?
You'll need something to determine the users operating system. This can be done by user agent detection. See this SO question: How to check website viewer's operating system?
Then, one option would be to put a fixed position hidden div in that corner and on hover, show your div.
Psuedo code could look like
HTML:
<div id="trigger-div" class="trigger-div"></div>
<div id="annoying-div" class="hidden">PLEASE DON'T LEAVE ME!</div>
CSS:
.hidden {display: none} // may or may not be appropriate. Could use visibility or opacity
.trigger-div {position: fixed; height: 100px; width: 100px; top: 0;}
.trigger-div.windows {right: 0;}
.trigger-div.mac {left: 0;}
Psuedo JS:
jQuery(function () {
var OS = navigator.platform;
if (OS === 'MacIntel') {
jQuery('#trigger-div').addClass('mac');
} else if (OS === 'Win32') {
jQuery('#trigger-div').addClass('windows');
} else {
// Maybe consider mobile?
jQuery('#trigger-div').hide();
}
}
jQuery('#trigger-div').on('hover', function () {
('#annoying-div').removeClass('hidden');
});