html - How can I make a Div fully push another div offscreen?
问题描述
I have 8 flexbox Div's (2columns, 4rows) how do I make it so when I press a button inside the Div it animates and pushes the other off screen whilst it expands right across?
I have currently been able to fully expand the div and hide the other one which looks ok (reason I hid it is because it ends up being about 5px wide on the left of the screen, but I've been working on this all day and just need to see how it's done!
CSS:
.col2 {
flex: 1;
height: 300px;
margin: 5px;
border:1px solid black;
z-index: 1;
text-align: right;
}
.flex-grid {
display: flex;
}
HTML
<div class="flex-grid">
<div class="col2" id="box1"></div>
<div class="col2" id="box2"></div>
</div>
Tried lots of different jQuery animations but it just doesn't seem to move if it will take it off screen, even tried to do it just css with a push and expand class.
Really struggling so would appreciate any help! (If you're wanting me to show the jQuery I've used to get the subpar solution of hiding the left element and expanding the right one across then let me know)
解决方案
修改@JoelBonetR 的答案以使用 jQuery,您可以使用 mouseover 和 mouseleave 事件来捕获悬停事件。
$('.col2').on('mouseover', function(){
$(this).css({
'animation': '1s forwards',
'background-color': 'red',
'animation-name': 'example'
});
//hide other divs
$(this).siblings().fadeOut();
});
$('.col2').on('mouseleave', function(){
$(this).css({
'animation-name': 'none',
'background-color': 'white'
});
//show other divs
$(this).siblings().fadeIn();
});
.col2 {
flex: 1;
height: 300px;
margin: 5px;
border:1px solid black;
z-index: 1;
text-align: right;
}
.flex-grid {
display: flex;
}
@keyframes example {
from {min-width: 0;}
to {min-width: 99vw}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="flex-grid">
<div class="col2" id="box1"></div>
<div class="col2" id="box2"></div>
</div>
推荐阅读
- android - Wiegand 26b (Indala Lite) 作为 Android 上的 NFC
- xamarin.forms - 无法为 xamlctask xamarin.forms.target 构建项目
- java - 具有相同字段名称问题的 Jooq record.into(Pojo.class)
- arrays - 一个数组可以处理多少个项目 node.js
- java - 在 Hibernate-Envers 中,如何使实体的早期版本成为最新版本
- mongodb - MongoDB 匹配文档数组中的字段(如果存在),如果不存在 -> 跳过该字段的匹配
- php - php日期条件与yii2中的数据库日期时间
- linux - SSPI 提供程序:在 Kerberos 数据库 SQL 2017 Linux 中找不到服务器
- java - Android Studio Linear Layout Design issue
- jquery - FileResult 下载不触发