简体   繁体   English

当jQuery animate:left函数离开内部div模式时,如何在div内部隐藏div?

[英]How hide div inside div when inner div mode left by jquery animate:left function?

I have html: 我有html:

<div style='width:300px; height:40px; float:left;' class='outerDiv'>
    <div style='width:200px; height:40px; float:right;' class='innerDiv'>
        Some text


    </div>
</div>

I try to make small move div.innerDiv by: 我尝试通过以下方法使div.innerDiv小幅移动:

$('.innerDiv').animate({ left: '+=200px' });

Basic idea - when div.innerDiv move to border of div.outerDiv, div.outerDiv should hide part of div.innerDiv. 基本思想-当div.innerDiv移至div.outerDiv的边框时,div.outerDiv应隐藏div.innerDiv的一部分。 I stuck on css styles on div's. 我在div上停留在CSS样式上。

see here : jsfiddle 看到这里: jsfiddle

you need to set a position ( relative,absolute,fixed ) so the css left:200px can work. 您需要设置一个位置(相对,绝对,固定),以便CSS left:200px可以工作。

css : css:

.outerDiv {
  overflow:hidden;
 }
.innerDiv {
  position:relative;
 }

jq : jq:

$('.innerDiv').animate({ left: '+=200px' });

let me know if this was what you were looking for. 让我知道这是否是您想要的。

If i understand you correctly, you want to hide the outer div but show the inner div. 如果我正确理解您的意见,那么您想隐藏外部div但显示内部div。

You should not hide parent div, because if you hide parent div, child will be hidden. 您不应该隐藏父div,因为如果您隐藏父div,则子对象将被隐藏。

You can change the background color of the outer div. 您可以更改外部div的背景颜色。

js fiddle link js小提琴链接

$('.innerDiv').animate({left:'200px'}, {
complete: function () {
    $('.outerDiv').addClass('hide');
}
}
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM