z索引无法在jquery中使用悬停宽度效果
z-index not working with hover width effect in jquery
我正在创建一个ruby on rails应用程序,我在一行中有一个五个并排的图像。。。当我悬停在图像上时,我希望图像的宽度增加。。。现在宽度可以工作了,但问题是当我悬停在任何图像上时,最后一个图像会移到另一边。。我尝试了很多方法来添加z索引,但都没有成功。。。尝试从脚本和css中添加z索引,使用相对位置和其他方法,但现在仍然有效这是我的家.html.erb:
<div class="container-fluid" id="width-r">
<%= image_tag("wood1.jpg",class: "this h-h") %>
<%= image_tag("wood2.jpg",class: "this") %>
<%= image_tag("wood3.jpg",class: "this") %>
<%= image_tag("wood4.jpg",class: "this") %>
<%= image_tag("wood5.jpg",class: "this") %>
</div>
<div class="jumbotron">
<h1 align="center"> Here comes the ads</h1>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".this").mouseover(function(){
$(this).animate({width: "25%"},"fast");
});
$(".this").mouseout(function(){
$(this).animate({width: "20%"},"fast");
});
});
</script>
这是我的css/scss文件:
@import "bootstrap-sprockets";
@import "bootstrap";
.navbar {
background-color: #fff;
}
body {
height: 100%;
}
.this {
width: 20%;
float: left;
height: 581.55px;
}
.navbar-ma {
/* remove space between the navbar and the images below */
margin-bottom: 0px;
}
.jumbotron {
height: 220px;
margin-bottom: 0px;
}
.container-fluid {
padding: 0px;
}
z-index仅适用于具有position
样式的元素,即position: relative; position: absolute;
等。
将position: relative;
添加到.this
.this {
width: 20%;
float: left;
height: 581.55px;
position: relative;
z-index: 0;
transition: 0.25s;
}
.this:hover{
width: 25%;
z-index: 1;
}
您不需要为此使用JS。当您将鼠标悬停在html对象上时,:hover
会工作(transition: 0.25s;
在CSS中设置动画)
我刚刚解决了我的问题,想把它放在这里给有同样问题的人。。
我把我的图像放在另一个div中,并添加一些css(一些css是从试图帮助我解决这个问题的人那里得到的)。。。这是我的代码的更新
home.html.erb:
<div class="container-fluid" id="width-r">
<div class="this">
<%= image_tag("wood1.jpg", class: "inside") %>
</div>
<div class="this">
<%= image_tag("wood2.jpg",class: "inside" ) %>
</div>
<div class="this">
<%= image_tag("wood3.jpg", class: "inside") %>
</div>
<div class="this">
<%= image_tag("wood4.jpg", class: "inside") %>
</div>
<div class="this">
<%= image_tag("wood5.jpg", class: "inside") %>
</div>
</div>
<div class="jumbotron">
<h1 align="center"> Here come the ads</h1>
</div>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".inside").mouseover(function(){
$(this).css('z-index', '100');
$(this).animate({width: "105%"},"slow");
});
$(".inside").mouseout(function(){
$(this).css("z-index", '');
$(this).animate({width: "100%"},"slow");
});
});
</script>
这是我的css/scss(您也可以通过取消注释下面的css代码并从主页中删除js来使用css方式):
@import "bootstrap-sprockets";
@import "bootstrap";
.navbar {
background-color: #fff;
}
body {
height: 100%;
}
.width-r {
position: relative;
}
.this {
width: 20%;
float: left;
height: 581.55px;
position: relative;
}
.inside {
width: 100%;
float: left;
height: 581.55px;
position: absolute;
transition: 0.5s;
}
/*
.inside:hover {
z-index:100;
width: 110%;
}
*/
.navbar-ma {
/* remove space between the navbar and the images below */
margin-bottom: 0px;
}
.jumbotron {
height: 220px;
margin-bottom: 0px;
z-index: 0;
}
.container-fluid {
padding: 0px;
}
相关文章:
- 名称输入的索引
- 在jQuery中获取表的行索引
- 测试索引值是否等于某个数字的倍数
- 循环遍历数组中的特定索引
- 按照选项卡索引的顺序循环一个jQuery选择
- 当鼠标悬停在文本中的单词上时显示警报
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 手风琴可点击并悬停
- 在JavaScript中通过索引从对象数组中获取值
- 悬停功能触发器
- 如何在鼠标悬停时在另一个图像上滑动图像.
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 如何在鼠标悬停事件时添加索引
- 如何在鼠标悬停时获取选定的索引
- 按钮悬停效果在不同的 Z 索引上
- 改变z索引悬停边框
- z索引无法在jquery中使用悬停宽度效果
- 悬停时添加/删除z索引
- 如何在鼠标悬停时获取元素的索引值
- 需要索引项目数在数组上悬停