我有一个在容器内的元素,位置相对,当我将这个元素移出容器的一侧时,它消失了。但是我需要在它离开自己的容器后显示该元素。那么我怎样才能使该元素在它离开其容器的一侧后显示出来呢?
<div class="container">
<div class="moving-element">
</div>
</div>
$(element).animate({"top": "-100px"}, speed, easing, func);
我有一个在容器内的元素,位置相对,当我将这个元素移出容器的一侧时,它消失了。但是我需要在它离开自己的容器后显示该元素。那么我怎样才能使该元素在它离开其容器的一侧后显示出来呢?
<div class="container">
<div class="moving-element">
</div>
</div>
$(element).animate({"top": "-100px"}, speed, easing, func);
使用 CSS,您可以设置该元素的 z-index。
z-index: 999;
将确保它几乎总是在顶部(除非某些其他元素具有更高的 z-index 并且重叠)。
编辑
实际上,可能是您的 CSS 或其他冲突元素,请查看:
<style type="text/css">
.container {
height: 500px;
width: 500px;
background: red;
}
.moving-element {
position: relative;
height: 250px;
width: 250px;
background: blue;
}
</style>
<div class="container">
<div class="moving-element">
</div>
</div>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(function() {
$('.moving-element').animate({"top": "-100px"}, 1000);
});
</script>
为我工作。