-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimg-popup.js
41 lines (33 loc) · 1.17 KB
/
img-popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// https://codepen.io/Muhnad/pen/dMbXNb
$(function () {
"use strict";
function hide() {
$(".show").fadeOut(function() {
var $img = $(".img-show img");
$img.off("error");
$img.attr("src", "");
});
}
$("img.popup").click(function () {
//get the location of the image to be popped up
var $src = $(this).attr("src");
$(".show").fadeIn();
//locate the img element to load into
var $img = $(".img-show img");
//remove the last 4 chars, in case this is a thumbnail (blahblah.png.jpg)
var $original = $src.slice(0, -4);
//also remove "/thumbs/" from the beginning and add "/f/"
$original = "/f/" + $original.slice(8);
//try to get the original
$img.attr("src", $original);
//set the backup url in case this is not a thumbnail (blahblah.png)
$img.off("error"); $img.on("error", function(){this.src=$src});
});
$("span, .overlay").click(function () {
hide();
});
$(document).keyup(function(e) {
//ESC key closes the image popup
if (e.keyCode === 27) hide();
});
});