我有一个简单的链接列表,当您将鼠标悬停在它上面时,它会附加一个 div(从 XML 加载此 div 中的数据),并且在悬停时它会删除 div,但只有当鼠标在链接上缓慢移动时鼠标移动更多时才会发生这种情况快速然后通常在链接上然后它不会删除 div 这意味着没有触发 mouseout 事件
在前两个链接上积极移动鼠标,然后您可以看到 div 有时不会隐藏
这是我的演示链接http://ukcatonline.com/template/
这是我的代码:
$(document).ready(function () {
//vertical navigation js
$(".mainnav_v a").hover(
function (e) {
$this = $(this)
$this.stop().animate({ paddingLeft : '16px'}, 300);
var brand ="";
var category="designer_frames";
$this.each(function()
{
var title = this.title;
if ($this.is('a') && $this.attr('title') != '' && $this.attr('id')==category)
{
brand= this.title;
$.ajax({
type: "GET",
url: "xml/peek_menu.xml",
//ie bug : it send wrong datatype on localmachine
dataType: ($.browser.msie) ? "text" : "xml",
success: function(data) {
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
//could have used $(xml).find(category).each(function() but jquery is intelligent enough to know wat element is currently selected
$(category, xml).each(
function(){
$(brand,this).each(
function(){
var title = $(this).attr('title');
var imgurl = $(this).attr('imgurl');
var description = $(this).find('description').text();
var feature1 = $(this).find('feature1').text();
var feature2 = $(this).find('feature2').text();
var feature3 = $(this).find('feature3').text();
var feature4 = $(this).find('feature4').text();
var html = '<div id="peek_container"><img src="' + imgurl + '" alt="" /><br /><br /><h1>'+title+'</h1><br />';
html += '<p>' + description + '</p><br />';
html += '<ul><li>'+feature1+'</li><li>'+feature2+'</li><li>'+feature3+'</li><li>'+feature4+'</li></ul><br /></div>';
$this.parent().append(html);
}
);
}
);
}
}
);
}
});
},
function (e) {
$this = $(this);
$this.stop().animate({ paddingLeft : '6px' }, 300);
$this.siblings().remove();
}
);});
这是我的 HTML:
<ul class="mainnav_v">
<li><a href="#url" class="peek" title="Boss" id="designer_frames">Boss</a></li>
<li><a href="#url" title="Burberry" id="designer_frames">Burberry</a></li>
<li><a href="#url" title="Bvlgari" id="designer_frames">Bvlgari</a></li>
<li><a href="#url">Chanel</a></li>
<li><a href="#url">Diesel</a></li>
<li><a href="#url">Dior</a></li>