**Witam wszystkich! **
Tworzę sobie stronę www (do pokazywania prac graficznych - portfolio), i mam problem z dodaniem funkcjonalności do mojego projektu, a mianowicie - modala.
W skrócie: chcę, aby po kliknięciu na obrazek, pojawiał się modal z full-size obrazkiem wraz z jego podpisem.
Stosuję i modyfikuję template z strony html5up: https://html5up.net/landed
- Kłopot polega na tym, że stosując przykładowy kod z strony: https://jsfiddle.net/snowMonkey/f1zav0ge/
Obrazek wyświetla się, ale zaciemnienie działa od danej <section> do końca strony, a potrzebowałbym by się wyświetlała na całej stronie.
Chciałbym by kliknięcie gdziekolwiek zamykało tego modala.
2.Tylko stosując tą metodę tracę stylizację obiektów zawartą w span i div, a chciałbym by te stylizacje zostały (chyba że się nie da, to mogę sobie darować) dałoby się zostawić stylizację i dodać tą funkcjonalność?
3.Skoro już tu się pytam: jak zrobić, by nie wyświetlał się cały obrazek na kafelkach tylko jego fragment? (prace mają różne rozmiary i proporcje przez co robi się bałagan) Zależy mmi na równych rozmiarach tych kafelków np 300x400.
Moje próby rozwiązania problemu kończą się na czarnym modalu bez podpisu i obrazka, albo na "undefined" no i zaciemnieniem od <section>.
Wiem że dużo pytań, ale google i StackOverflow nie pomagają.
Pytałem się moich kolegów i oni niestety nie wiedzą jak mi pomóc.
Dziękuję serdecznie za pomoc.
Oto fragmenty kodów:
CSS
/* sprawdzam */
#myImg {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}
#myImg:hover {
opacity: 0.7;
}
.modal {
overflow-y: none;
display: none;
/* Hidden by default */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(0, 0, 0);
/* Fallback color */
background-color: rgba(0, 0, 0, 0.9);
/* Black w/ opacity */
}
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}
.modal-content,
#caption {
animation-name: zoom;
animation-duration: 0.6s;
}
@keyframes zoom {
from {
transform: scale(0)
}
to {
transform: scale(1)
}
}
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
@media only screen and (max-width: 700px) {
.modal-content {
width: 100%;
}
}
/*koniec*/
/* Image */
.image {
border-radius: 4px;
border: 0;
display: inline-block;
position: relative;
overflow: hidden;
cursor: pointer;
}
.image:hover {opacity: 0.7;}
.image:before {
content: '';
display: block;
position: absolute;
left: 0;
top: 0;
/*background-image: url("images/overlay.png");*/
width: 100%;
height: 100%;
z-index: 1;
}
.image img {
border-radius: 4px;
display: block;
}
.image.left {
float: left;
margin: 0 1.5em 1em 0;
top: 0.25em;
}
.image.right {
float: right;
margin: 0 0 1em 1.5em;
top: 0.25em;
}
.image.left, .image.right {
max-width: 40%;
}
.image.left img, .image.right img {
width: 100%;
}
.image.fit {
display: block;
margin: 0 0 2em 0;
width: 100%;
}
.image.fit img {
width: 100%;
}
.modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 100px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
}
/* Modal Content (image) */
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
}
/* Caption of Modal Image */
#caption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}
/* Add Animation */
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}
@-webkit-keyframes zoom {
from {-webkit-transform:scale(0)}
to {-webkit-transform:scale(1)}
}
@keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}
/* The Close Button */
.close {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
.modal-content {
width: 100%;
}
}
HTML:
<section>
<div class="box alt">
<div class="row gtr-50 gtr-uniform">
<div class="col-4 col-6-xsmall"><span class="image fit"><img src="images/pic03.jpg" alt="" /></span></div> <!-- oryginal --->
<div class="col-4 col-6-xsmall"><img class="myImg"src="images/portfolio/obrazek.png" alt="Kenobi"/></span></div>
</div>
</div>
</section>
<!--
<section>
<img class="myImages" id="myImg" src="http://onebigphoto.com/uploads/2012/10/midnight-sun-in-lofoten-norway.jpg" alt="Midnight sun in Lofoten, Norway" width="300" height="200">
<img class="myImages" id="myImg" src="http://cdn-image.travelandleisure.com/sites/default/files/styles/1600x1000/public/1490029386/fisherman-cabin-hamnoy-lofoten-islands-norway-NORWAY0320.jpg?itok=cpPuUjh1" alt="Fishermen's cabins in Lofoten, Norway" width="300" height="200">
<img class="myImages" id="myImg" src="http://fjordtours.blob.core.windows.net/fjordtours-umbraco/1199/gerirangerfjord-per-ottar-walderhaug-fjordnorway.jpg" alt="Gerirangerfjord, Norway" width="300" height="200">
-->
<div id="myModal" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
</section>
JS
// create references to the modal...
var modal = document.getElementById('myModal');
// to all images -- note I'm using a class!
var images = document.getElementsByClassName('col-4 col-6-xsmall');
// the image in the modal
var modalImg = document.getElementById("image fit");
// and the caption in the modal
var captionText = document.getElementById("caption");
// Go through all of the images with our custom class
for (var i = 0; i < images.length; i++) {
var img = images[i];
// and attach our click listener for this image.
img.onclick = function(evt) {
console.log(evt);
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
}
var span = document.getElementsByClassName("close")[0];
span.onclick = function() {
modal.style.display = "none";
}