1 // jQuery Autohide v1.0.2 2 // (c) 2014 Alex Taujenis 3 // MIT License 4 5 (function($) { 6 return $.fn.autohide = function(opts) { 7 var Delay; 8 Delay = (function() { 9 Delay.prototype.timeout = 1000; 10 11 function Delay(el, opts) { 12 this.el = el; 13 if ((opts != null) && ("timeout" in opts)) { 14 this.timeout = parseInt(opts["timeout"]); 15 } 16 $(window).mousemove(((function(_this) { 17 return function() { 18 return _this.mouseDelay(); 19 }; 20 })(this))); 21 this; 22 } 23 24 Delay.prototype.mouseDelay = function() { 25 if (!this.shown) { 26 this.showMouse(); 27 } 28 window.clearTimeout(this.mouse_timeout); 29 this.mouse_timeout = window.setTimeout(((function(_this) { 30 return function() { 31 return _this.hideMouse(); 32 }; 33 })(this)), this.timeout); 34 }; 35 36 Delay.prototype.showMouse = function() { 37 this.el.css("cursor", "default"); 38 this.shown = true; 39 }; 40 41 Delay.prototype.hideMouse = function() { 42 this.el.css("cursor", "none"); 43 this.shown = false; 44 }; 45 46 return Delay; 47 48 })(); 49 new Delay(this, opts); 50 return this; 51 }; 52 })(jQuery);
相关文章: