Skip to content
Permalink
Browse files

Make images clickable

When you click an image, you now get the full size image in a modal box.
This makes things easier for people that are going blind, like me.
  • Loading branch information
rkuris committed Jan 29, 2020
1 parent 34e4623 commit b5080575f49488444f1db2dd2c75f8785ca5979b
Showing with 220 additions and 2 deletions.
  1. +21 −0 assets/clickableImages.js
  2. +102 −0 assets/css/style.css
  3. +89 −1 assets/sass/style.scss
  4. +8 −1 post.hbs
@@ -0,0 +1,21 @@
var modal = document.getElementById("myModal");
var modalImg = document.getElementById("img01");

var post = document.getElementById("post");
var clickables = post.querySelectorAll("img");
var i;
for (i = 0; i < clickables.length; i++) {
var img = clickables[i];
img.onclick = function() {
modal.style.display = "block";
modalImg.src = this.src;
}
}

var span = document.getElementById("closeSpan")
span.onclick = function() {
modal.style.display = "none";
}
modalImg.onclick = function() {
modal.style.display = "none";
}
@@ -519,3 +519,105 @@ code {
padding: 1em 0;
margin-bottom: 2em;
}

table {
border-collapse: collapse;
}

table, th, td {
border: 1px solid black;
}

/* Style the Image Used to Trigger the Modal (was myImg*/
#popUpOnClick {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}

#popUpOnClick:hover {
opacity: 0.7;
}

/* The Modal (background) */
.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: black;
/* 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 (Image Text) - Same Width as the Image */
#modalCaption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}

/* Add Animation - Zoom in the Modal */
.modal-content, #modalCaption {
animation-name: zoom;
animation-duration: 0.6s;
}

@keyframes zoom {
from {
transform: scale(0);
}
to {
transform: scale(1);
}
}
/* The Close Button */
.modalClose {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}

.modalClose:hover,
.modalClose: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%;
}
}
@@ -347,4 +347,92 @@ code {
.contentpost_footer_page {
padding: 1em 0;
margin-bottom: 2em;
}
}

table {
border-collapse: collapse;
}

table, th, td {
border: 1px solid black;
}

/* Style the Image Used to Trigger the Modal (was myImg*/
#popUpOnClick {
border-radius: 5px;
cursor: pointer;
transition: 0.3s;
}

#popUpOnClick:hover {opacity: 0.7;}

/* The Modal (background) */
.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 (Image Text) - Same Width as the Image */
#modalCaption {
margin: auto;
display: block;
width: 80%;
max-width: 700px;
text-align: center;
color: #ccc;
padding: 10px 0;
height: 150px;
}

/* Add Animation - Zoom in the Modal */
.modal-content, #modalCaption {
animation-name: zoom;
animation-duration: 0.6s;
}

@keyframes zoom {
from {transform:scale(0)}
to {transform:scale(1)}
}

/* The Close Button */
.modalClose {
position: absolute;
top: 15px;
right: 35px;
color: #f1f1f1;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}

.modalClose:hover,
.modalClose: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%;
}
}
@@ -4,7 +4,7 @@
{{#post}}
{{#if tags}}<span class="contentpost_meta">{{tags separator=" · "}}</span>{{/if}}
<h1 class="contentpost_headline post-title" itemprop="url" data-pjax title="{{{title}}}">{{{title}}}</h1>
<section class="contentpost_articlecontent post-content">
<section class="contentpost_articlecontent post-content" id="post">
{{content}}
</section>
<footer class="contentpost_footer post-footer">
@@ -25,4 +25,11 @@
<script src="/commento/assets/js/commento.js"></script>
<noscript>Please enable JavaScript to view the <a href="https://github.com/adtac/commento">comments powered by commento</a></noscript>
</article>
<!-- The Modal popup for making images bigger -->
<div id="myModal" class="modal">
<span id="closeSpan" class="modalClose">&times;</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
</main>
<script src="/assets/clickableImages.js"></script>

0 comments on commit b508057

Please sign in to comment.
You can’t perform that action at this time.