关于延迟顺序显示, 怎么敲代码才能优雅实现?

鼠标移入<p id="test">test</p>, 2秒后在<p id="info"></p>中提示mouseenter.

鼠标移出<p id="test">test</p>, 在<p id="info"></p>中提示mouseleave.

要求leave的信息必须等mouseenter显示后,再显示(有顺序)。 应该怎么写事件?


MMTTMM
浏览 411回答 1
1回答

12345678_0001

Try this:var $test = $('#test'),&nbsp; &nbsp; $info = $('#info'),&nbsp; &nbsp; status;$test.on('mouseenter',function(){&nbsp; &nbsp; status = "";&nbsp; &nbsp; $info.text('mouseenter').fadeOut(0).delay(2000).fadeIn(300, function(){&nbsp; &nbsp; &nbsp; &nbsp; status === "out" ? $(this).text('mouseleave') : status = "in";&nbsp; &nbsp; });});$test.on('mouseout',function(){&nbsp; &nbsp; status === "in" ? $info.text('mouseleave') : status = "out";});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript