水平菜单动态添加div

嗨我试图在我的滑动面板之间添加红色的div。 当您进入菜单项并且面板滑出时,我的菜单会动画,但在每个面板之间我想以动态方式添加/删除面板。 当我说删除我的意思是当你向后通过菜单,滑动面板缩回你,然后删除最后一个红色div,当你mouseenter一个菜单项和滑动面板exapand你添加一个红色div(5px宽无关紧要高度)这是我到目前为止所拥有的。 的jsfiddle

$(document).ready(function () { $('.menu-item').mouseenter(function () { var curr = $(this).closest('.container'); var next = curr.next('.container'); next.animate({ 'left': curr.position().left + curr.width() + 5 }); if(curr.index() < ($('.container').length - 1)){ here i need to add and remove a 
to the right side of the current(var curr) div } var $index = curr.index() + 1; $('.container:nth-child(' + $index + ')').nextAll().each(function () { $(this).animate({ 'left': curr.position().left + curr.width() + 5 }); }); }); }); .spacer { background-color:Red; width:5px; height:200px; position:absolute; z-index:1000; }

在这里……如果这是好的,那就不要害羞但是看看这里: DEMO

编辑

那么这是另一个解决方案: DEMO2

Interesting Posts