我有一组产品类别。每个类别都有一些产品图片。我创建了一个父 div,它有一个溢出:隐藏的 CSS 值。我想实现鼠标悬停效果。一旦您将鼠标悬停在我想显示相关类别产品图像的类别上。我尝试了很多但仍然没有得到完美的解决方案这是一个小片段:这是我的Fiddle Demo
<div class="menu" id="1" style="width:200px;">
<a href="#">category 1</a>
</div>
<div class="flyout hidden" id="12">
<div class="list">
<ul>
<li><span class="box">1</span></li>
<li><span class="box">2</span></li>
<li><span class="box">3</span></li>
<li><span class="box">4</span></li>
<li><span class="box">5</span></li>
<li><span class="box">6</span></li>
<li><span class="box">7</span></li>
<li><span class="box">8</span></li>
<li><span class="box">9</span></li>
</ul>
</div>
<button class="prev">prev</button>
<button class="more">more</button>
</div><br><br>
<div class="menu" id="2" style="width:200px;">
<a href="#">category 2</a>
</div>
<div class="flyout hidden" id="11" >
<div class="list">
<ul>
<li><span class="box">11</span></li>
<li><span class="box">12</span></li>
<li><span class="box">13</span></li>
<li><span class="box">14</span></li>
<li><span class="box">15</span></li>
<li><span class="box">16</span></li>
<li><span class="box">17</span></li>
<li><span class="box">18</span></li>
<li><span class="box">19</span></li>
</ul>
</div>
<button class="prev">prev</button>
<button class="more">more</button>
</div>
//脚本
$(".more").click(function(){
$(".list").animate({scrollLeft: "+=330"}, 300, "swing");
});
$(".prev").click(function(){
$(".list").animate({scrollLeft: "-=330"}, 300, "swing");
});
$(".menu").hover(function(){
var gal_id =$(this).next().attr('id');
//alert(gal_id);
var id='#'+gal_id;
$(id).removeClass('hidden');
},function(){
$(id).addClass('hidden');
});
//CSS
body {
margin: 5px;
}
.list {
overflow: hidden;
height:110px;
width: 353px;
margin-left: -38px;
}
ul {
overflow: hidden;
width:2000px;
}
li {
float: left;
}
.box {
width: 100px;
height: 100px;
background: #33cccc;
margin: 5px;
display: block;
}
.flyout{
position:absolute;
width:320px;
height:250px;
margin-left:20px;
background:red;
overflow: hidden;
z-index:10000;
}
.hidden{
visibility: hidden;
}