【发布时间】:2015-01-11 12:36:24
【问题描述】:
我遇到了与下面的 sn-p 类似的问题:
$('button').click(function(){
var p = $('<p>Lorem</p>');
$('body').prepend(p);
p.effect("highlight", {}, 3000);
});
$(document).on('mouseenter', 'p', function(){
$(this).css('background', 'blue');
});
$(document).on('mouseleave', 'p', function(){
$(this).css('background', 'white');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<button>Add</button>
如您所见,只要将第一个 Lorem 添加到正文中,mouseenter 就会被允许在几分之一秒内出现。结果,您会看到它的蓝色背景。
这会对用户体验产生负面影响。
如何防止这种情况发生?
【问题讨论】:
标签: javascript jquery jquery-ui highlight mouseenter