我想要一个特定的div在用户盘旋时展开。
<td><h4>Like Football</h4></td>
我不清楚如何访问div标签内的元素。我还希望扩展div的背景在某种程度上是透明的,就像在显示Fifa 12的this website上所做的那样。 请帮忙。
<div>
<a href="">
<img src="images/fifa.jpg" /></a>
</div>
<div class="wrapper">
<table>
<tr>
<td>
<img src="images/arrow.jpg" height="28" width="28"/ >
</td>
<td>
<h4>Like Football</h4>
</td>
</tr>
</table>
<div class="wrapperhover">
<p class="wrappercontent" id="p">
<span>Download FIFA 12 on Xperia™!</span>
<a href="" onclick=""><span>Find more</span></a>
</p>
</div>
</div>
CSS
.wrapper
{
background-color:Black;
color:White;
width:245px;
height:100px;
margin-top:-100px;
position:absolute;
}
.wrapperhover
{
height:100px;
}
JQUERY
$(document).ready(function(){
$(".wrapperhover").hide();
$(".wrapper").hover(function () {
$(".wrapperhover").show();
var contentHeight = 0;
$(this).children().each(function () {
contentHeight += $(this).height();
});
$(this).animate({
height: '150px',
marginTop: "-150"
}, 300);
}, function () {
$(this).animate({
height: '100px', marginTop: "-100"
}, 300);
$(".wrapperhover").hide();
});
});
答案 0 :(得分:2)
我做了一个小提琴here。在看到你正在寻找的一个例子后,我认为接近你想要的。你可能不得不调整一些渐变css,但我认为这个想法就在那里。这适用于所有浏览器。透明度没有添加到您提到的网站中,它从一开始就存在,所以我在.wrapper div中添加了一个类.gradient
。这是代码:
<div class="wrapper gradient">
<table>
<tr>
<td>
<img src="http://www.freeclipartnow.com/d/40228-1/arrow-blue-rounded-right.jpg" height="28" width="28"/ >
</td>
<td>
<h4> Like Football</h4>
</td>
</tr>
</table>
<div class="wrapperhover">
<p class="wrappercontent" id="p">
<span>Download FIFA 12 on Xperia™!</span>
<a href="" onclick=""><span>Find more</span></a>
</p>
</div>
</div>
由于我们可以使用css,因此js与此答案无关。如果您需要查看js,请参阅上面的小提琴。这是我使用this渐变编辑器添加的CSS:
.gradient
{
background: -moz-linear-gradient(top, rgba(40,52,59,1) 21%, rgba(40,52,59,0.82) 35%, rgba(130,140,149,0.3) 76%, rgba(181,189,200,0) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(21%,rgba(40,52,59,1)), color-stop(35%,rgba(40,52,59,0.82)), color-stop(76%,rgba(130,140,149,0.3)), color-stop(100%,rgba(181,189,200,0))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(40,52,59,1) 21%,rgba(40,52,59,0.82) 35%,rgba(130,140,149,0.3) 76%,rgba(181,189,200,0) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(40,52,59,1) 21%,rgba(40,52,59,0.82) 35%,rgba(130,140,149,0.3) 76%,rgba(181,189,200,0) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(40,52,59,1) 21%,rgba(40,52,59,0.82) 35%,rgba(130,140,149,0.3) 76%,rgba(181,189,200,0) 100%); /* IE10+ */
background: linear-gradient(top, rgba(40,52,59,1) 21%,rgba(40,52,59,0.82) 35%,rgba(130,140,149,0.3) 76%,rgba(181,189,200,0) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#28343b', endColorstr='#00b5bdc8',GradientType=0 ); /* IE6-9 */
}