我只是想根据周围的空间获得鼠标悬停div的位置。不知何故,我能够在前两列做到这一点,但不能用于其他列。可能是我写的条件状态写错了。无法计算悬停元素的确切位置
任何人都可以请帮忙吗?
JS小提琴网址:
http://jsfiddle.net/mufeedahmad/2u1zr11f/7/
JS代码:
$('.thumb-over-team li').find('.cover').css({opacity:0});
$('.thumb-over-team li').on('mouseenter', function(){
var $this = $(this),
thisoffset = $this.position().left,
openDivId = $(this).find('.cover'),
thumbContainer = '.thumb-over-team',
speedanim = 200;
if(thisoffset + openDivId.outerWidth() >= $(thumbContainer).outerWidth()){
//thisoffset = $(thumbContainer).outerWidth() - openDivId.outerWidth() - 212;
thisoffset = thisoffset - openDivId.outerWidth()+10;
openDivId.stop().css({'z-index':'9999'}).animate({'opacity':'1', 'left':-thisoffset}, 200);
}else{
openDivId.stop().css({'z-index':'9999'}).animate({'opacity':'1', 'left':'212px'}, 200);
}
}).on('mouseleave', function(){
$(this).find('.cover').stop().css({'z-index':'-1'}).animate({'opacity':'0', 'left':'200px'}, 200);
});
$('.close-parent').on('click', function(){
$(this).parents('.cover').stop().css({'z-index':'-1'}).animate({'opacity':'0', 'left':'200px'}, 200);
});;
你正在试图做什么的还不清楚的内盖,什么是理想的结果?如果你看看你的帖子标题:'无法计算悬停元素的确切位置' - 答案很简单,使用'on('hover',function ...'event或'hover()'函数并检查 – odedta
看起来'.cover'在'.thumb-over-team'里面,所以这个可扩展的方块('.cover')将它的宽度加到容器的总宽度上('.thumb-over-团队“),因此你的条件”认为“'。cover'仍然可以放在'.thumb-over-team'的宽度内,如'($(thumbContainer).outerWidth())所计算' –