/** * 个股导航菜单悬停交互。 */ (function ($) { 'use strict'; if (!$) { return; } $.fn.hoverDelay = function (options) { var defaults = { hoverDuring: 200, outDuring: 200, hoverEvent: function () { $.noop(); }, outEvent: function () { $.noop(); } }; var sets = $.extend(defaults, options || {}); var hoverTimer; var outTimer; return $(this).each(function () { $(this).hover(function () { clearTimeout(outTimer); hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring); }, function () { clearTimeout(hoverTimer); outTimer = setTimeout(sets.outEvent, sets.outDuring); }); }); }; $(function () { var $li = $('#sta_menu li'); var $currentMenuLink; $li.each(function () { var $this = $(this); if ($this.children('a').attr('class') === 'cur') { $currentMenuLink = $this.children('a'); } $this.hoverDelay({ outDuring: 200, hoverDuring: 200, hoverEvent: function () { $this.children('a').addClass('cur'); $this.addClass('ShowChildMenu'); }, outEvent: function () { $this.removeClass('ShowChildMenu'); if ($currentMenuLink && $currentMenuLink.html() !== $this.children('a').html()) { $this.children('a').removeClass('cur'); } } }); }); }); }(window.jQuery));