2016-05-25 13 views
1

Ich versuche, eine Hover-Beschriftung zu erstellen, die sich selbst bei der Größenanpassung an die gesamte Bildbreite und -höhe anpasst. Ich habe versucht, einen Jquery-Code zu verwenden, den ich hier gefunden habe, aber ich war nicht in der Lage, herauszufinden, wie es funktioniert.Wie mache ich meine Hover-Beschriftung, um die gesamte Bildgröße abzudecken?

$(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{ 
 
\t \t list-style-type: none; 
 
\t \t margin: 0px; 
 
\t \t padding: 0px; 
 
\t \t 
 
\t } 
 

 
\t .caption-style-1 li{ 
 
\t \t float: left; 
 
\t \t padding: 0px; 
 
\t \t position: relative; 
 
\t \t overflow: hidden; 
 
\t } 
 

 
\t .caption-style-1 li:hover .caption{ 
 
\t \t opacity: 1; 
 

 
\t } 
 

 

 
\t .caption-style-1 img{ 
 
\t \t margin: 0px; 
 
\t \t padding: 0px; 
 
\t \t float: left; 
 
\t \t z-index: 4; 
 
\t } 
 

 

 
\t .caption-style-1 .caption{ 
 
\t \t cursor: pointer; 
 
\t \t position: absolute; 
 
\t \t opacity: 0; 
 
\t \t -webkit-transition:all 0.45s ease-in-out; 
 
\t \t -moz-transition:all 0.45s ease-in-out; 
 
\t \t -o-transition:all 0.45s ease-in-out; 
 
\t \t -ms-transition:all 0.45s ease-in-out; 
 
\t \t transition:all 0.45s ease-in-out; 
 

 
\t } 
 
\t .caption-style-1 .blur{ 
 
\t \t background-color: rgba(0,0,0,0.65); 
 
    position: absolute; 
 
\t \t height: 500px; 
 
\t \t width: 400px; 
 
\t \t z-index: 5; 
 
\t \t position: relative; 
 
\t } 
 

 
\t .caption-style-1 .caption-text h1{ 
 
\t \t text-transform: uppercase; 
 
\t \t font-size: 24px; 
 
\t } 
 
\t .caption-style-1 .caption-text{ 
 
\t \t z-index: 10; 
 
\t \t color: #fff; 
 
\t \t position: absolute; 
 
\t \t width: 400px; 
 
\t \t height: 500px; 
 
\t \t text-align: center; 
 
\t \t top:100px; 
 
\t } 
 

 
.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"> 
 
\t \t <ul class="caption-style-1"> 
 
\t \t \t <li> 
 
\t \t \t \t <img class="imagen" src="http://uploads5.wikiart.org/images/claude-monet/the-summer-poppy-field.jpg"/" alt=""> 
 
\t \t \t \t <div class="caption"> 
 
\t \t \t \t \t <div class="blur"></div> 
 
\t \t \t \t \t <div class="caption-text"> 
 
\t \t \t \t \t \t <h1>Amazing Caption</h1> 
 
\t \t \t \t \t \t <p>Whatever It Is - Always Awesome</p> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t </li> 
 
    </ul> 
 
</div>

+0

Aber es Anpassung ist bereits auf die volle Höhe und Breite des Bildes. [JSFiddle] (https://jsfiddle.net/sz3ywc1o/) –

+0

Ich machte ein Schnipsel, um es dir zu zeigen :) –

+0

Schau dir meine Antwort an. Ich denke, was Sie suchen :) –

Antwort

1

Dann haben Sie gerade auch die height Eigentum Ihrer image auf Ihre .blur Klasse hinzuzufügen.

$(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{ 
 
\t \t list-style-type: none; 
 
\t \t margin: 0px; 
 
\t \t padding: 0px; 
 
\t \t 
 
\t } 
 

 
\t .caption-style-1 li{ 
 
\t \t float: left; 
 
\t \t padding: 0px; 
 
\t \t position: relative; 
 
\t \t overflow: hidden; 
 
\t } 
 

 
\t .caption-style-1 li:hover .caption{ 
 
\t \t opacity: 1; 
 

 
\t } 
 

 

 
\t .caption-style-1 img{ 
 
\t \t margin: 0px; 
 
\t \t padding: 0px; 
 
\t \t float: left; 
 
\t \t z-index: 4; 
 
\t } 
 

 

 
\t .caption-style-1 .caption{ 
 
\t \t cursor: pointer; 
 
\t \t position: absolute; 
 
\t \t opacity: 0; 
 
\t \t -webkit-transition:all 0.45s ease-in-out; 
 
\t \t -moz-transition:all 0.45s ease-in-out; 
 
\t \t -o-transition:all 0.45s ease-in-out; 
 
\t \t -ms-transition:all 0.45s ease-in-out; 
 
\t \t transition:all 0.45s ease-in-out; 
 

 
\t } 
 
\t .caption-style-1 .blur{ 
 
\t \t background-color: rgba(0,0,0,0.65); 
 
    position: absolute; 
 
\t \t height: 500px; 
 
\t \t width: 400px; 
 
\t \t z-index: 5; 
 
\t \t position: relative; 
 
\t } 
 

 
\t .caption-style-1 .caption-text h1{ 
 
\t \t text-transform: uppercase; 
 
\t \t font-size: 24px; 
 
\t } 
 
\t .caption-style-1 .caption-text{ 
 
\t \t z-index: 10; 
 
\t \t color: #fff; 
 
\t \t position: absolute; 
 
\t \t width: 400px; 
 
\t \t height: 500px; 
 
\t \t text-align: center; 
 
\t \t top:100px; 
 
\t } 
 

 
.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"> 
 
\t \t <ul class="caption-style-1"> 
 
\t \t \t <li> 
 
\t \t \t \t <img class="imagen" src="http://uploads5.wikiart.org/images/claude-monet/the-summer-poppy-field.jpg"/" alt=""> 
 
\t \t \t \t <div class="caption"> 
 
\t \t \t \t \t <div class="blur"></div> 
 
\t \t \t \t \t <div class="caption-text"> 
 
\t \t \t \t \t \t <h1>Amazing Caption</h1> 
 
\t \t \t \t \t \t <p>Whatever It Is - Always Awesome</p> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </div> 
 
\t \t \t </li> 
 
    </ul> 
 
</div>

+1

danke, es funktioniert! –