如何使我的悬停标题覆盖整个图像大小?
How do i make my hover caption to cover the whole image size?
我正在尝试制作一个悬停字幕,即使在调整大小时也能适应整个图像的宽度和高度。我已经尝试使用我在此处找到的 jquery 代码,但我无法弄清楚如何使其工作。
$(document).ready(function() {
var imgWidth = $('.imagen').width();
$('.caption-text').css({width: imgWidth});
$('.caption-style-1').css({width: imgWidth});
$('.blur').css({width: imgWidth});
});
.container-a1 {
height: 100%;
width: 100%;
}
.caption-style-1{
list-style-type: none;
margin: 0px;
padding: 0px;
}
.caption-style-1 li{
float: left;
padding: 0px;
position: relative;
overflow: hidden;
}
.caption-style-1 li:hover .caption{
opacity: 1;
}
.caption-style-1 img{
margin: 0px;
padding: 0px;
float: left;
z-index: 4;
}
.caption-style-1 .caption{
cursor: pointer;
position: absolute;
opacity: 0;
-webkit-transition:all 0.45s ease-in-out;
-moz-transition:all 0.45s ease-in-out;
-o-transition:all 0.45s ease-in-out;
-ms-transition:all 0.45s ease-in-out;
transition:all 0.45s ease-in-out;
}
.caption-style-1 .blur{
background-color: rgba(0,0,0,0.65);
position: absolute;
height: 500px;
width: 400px;
z-index: 5;
position: relative;
}
.caption-style-1 .caption-text h1{
text-transform: uppercase;
font-size: 24px;
}
.caption-style-1 .caption-text{
z-index: 10;
color: #fff;
position: absolute;
width: 400px;
height: 500px;
text-align: center;
top:100px;
}
.imagen {
height: 800px;
width: 800px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-a1">
<ul class="caption-style-1">
<li>
<img class="imagen" src="http://uploads5.wikiart.org/images/claude-monet/the-summer-poppy-field.jpg"/" alt="">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>Amazing Caption</h1>
<p>Whatever It Is - Always Awesome</p>
</div>
</div>
</li>
</ul>
</div>
然后,您只需将 image
的 height
属性 添加到 .blur
class。
$(document).ready(function() {
var imgWidth = $('.imagen').width();
var imgHeight = $('.imagen').height();
$('.caption-text').css({width: imgWidth});
$('.caption-style-1').css({width: imgWidth});
$('.blur').css({width: imgWidth, height: imgHeight});
});
.container-a1 {
height: 100%;
width: 100%;
}
.caption-style-1{
list-style-type: none;
margin: 0px;
padding: 0px;
}
.caption-style-1 li{
float: left;
padding: 0px;
position: relative;
overflow: hidden;
}
.caption-style-1 li:hover .caption{
opacity: 1;
}
.caption-style-1 img{
margin: 0px;
padding: 0px;
float: left;
z-index: 4;
}
.caption-style-1 .caption{
cursor: pointer;
position: absolute;
opacity: 0;
-webkit-transition:all 0.45s ease-in-out;
-moz-transition:all 0.45s ease-in-out;
-o-transition:all 0.45s ease-in-out;
-ms-transition:all 0.45s ease-in-out;
transition:all 0.45s ease-in-out;
}
.caption-style-1 .blur{
background-color: rgba(0,0,0,0.65);
position: absolute;
height: 500px;
width: 400px;
z-index: 5;
position: relative;
}
.caption-style-1 .caption-text h1{
text-transform: uppercase;
font-size: 24px;
}
.caption-style-1 .caption-text{
z-index: 10;
color: #fff;
position: absolute;
width: 400px;
height: 500px;
text-align: center;
top:100px;
}
.imagen {
height: 800px;
width: 800px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-a1">
<ul class="caption-style-1">
<li>
<img class="imagen" src="http://uploads5.wikiart.org/images/claude-monet/the-summer-poppy-field.jpg"/" alt="">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>Amazing Caption</h1>
<p>Whatever It Is - Always Awesome</p>
</div>
</div>
</li>
</ul>
</div>
我正在尝试制作一个悬停字幕,即使在调整大小时也能适应整个图像的宽度和高度。我已经尝试使用我在此处找到的 jquery 代码,但我无法弄清楚如何使其工作。
$(document).ready(function() {
var imgWidth = $('.imagen').width();
$('.caption-text').css({width: imgWidth});
$('.caption-style-1').css({width: imgWidth});
$('.blur').css({width: imgWidth});
});
.container-a1 {
height: 100%;
width: 100%;
}
.caption-style-1{
list-style-type: none;
margin: 0px;
padding: 0px;
}
.caption-style-1 li{
float: left;
padding: 0px;
position: relative;
overflow: hidden;
}
.caption-style-1 li:hover .caption{
opacity: 1;
}
.caption-style-1 img{
margin: 0px;
padding: 0px;
float: left;
z-index: 4;
}
.caption-style-1 .caption{
cursor: pointer;
position: absolute;
opacity: 0;
-webkit-transition:all 0.45s ease-in-out;
-moz-transition:all 0.45s ease-in-out;
-o-transition:all 0.45s ease-in-out;
-ms-transition:all 0.45s ease-in-out;
transition:all 0.45s ease-in-out;
}
.caption-style-1 .blur{
background-color: rgba(0,0,0,0.65);
position: absolute;
height: 500px;
width: 400px;
z-index: 5;
position: relative;
}
.caption-style-1 .caption-text h1{
text-transform: uppercase;
font-size: 24px;
}
.caption-style-1 .caption-text{
z-index: 10;
color: #fff;
position: absolute;
width: 400px;
height: 500px;
text-align: center;
top:100px;
}
.imagen {
height: 800px;
width: 800px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-a1">
<ul class="caption-style-1">
<li>
<img class="imagen" src="http://uploads5.wikiart.org/images/claude-monet/the-summer-poppy-field.jpg"/" alt="">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>Amazing Caption</h1>
<p>Whatever It Is - Always Awesome</p>
</div>
</div>
</li>
</ul>
</div>
然后,您只需将 image
的 height
属性 添加到 .blur
class。
$(document).ready(function() {
var imgWidth = $('.imagen').width();
var imgHeight = $('.imagen').height();
$('.caption-text').css({width: imgWidth});
$('.caption-style-1').css({width: imgWidth});
$('.blur').css({width: imgWidth, height: imgHeight});
});
.container-a1 {
height: 100%;
width: 100%;
}
.caption-style-1{
list-style-type: none;
margin: 0px;
padding: 0px;
}
.caption-style-1 li{
float: left;
padding: 0px;
position: relative;
overflow: hidden;
}
.caption-style-1 li:hover .caption{
opacity: 1;
}
.caption-style-1 img{
margin: 0px;
padding: 0px;
float: left;
z-index: 4;
}
.caption-style-1 .caption{
cursor: pointer;
position: absolute;
opacity: 0;
-webkit-transition:all 0.45s ease-in-out;
-moz-transition:all 0.45s ease-in-out;
-o-transition:all 0.45s ease-in-out;
-ms-transition:all 0.45s ease-in-out;
transition:all 0.45s ease-in-out;
}
.caption-style-1 .blur{
background-color: rgba(0,0,0,0.65);
position: absolute;
height: 500px;
width: 400px;
z-index: 5;
position: relative;
}
.caption-style-1 .caption-text h1{
text-transform: uppercase;
font-size: 24px;
}
.caption-style-1 .caption-text{
z-index: 10;
color: #fff;
position: absolute;
width: 400px;
height: 500px;
text-align: center;
top:100px;
}
.imagen {
height: 800px;
width: 800px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="container-a1">
<ul class="caption-style-1">
<li>
<img class="imagen" src="http://uploads5.wikiart.org/images/claude-monet/the-summer-poppy-field.jpg"/" alt="">
<div class="caption">
<div class="blur"></div>
<div class="caption-text">
<h1>Amazing Caption</h1>
<p>Whatever It Is - Always Awesome</p>
</div>
</div>
</li>
</ul>
</div>