-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
executable file
·89 lines (61 loc) · 2.84 KB
/
index.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="http://jquery-ui-for-ipad-and-iphone.googlecode.com/files/jquery.ui.ipad.js"></script>
<script type="text/javascript">
$(function(){
// Loop through all the sets of before and after pics
$(".beforeafter").each(function(){
// Set the container's size to the size of the image
$(this).width($(this).find("img[rel=before]").attr("width")).height($(this).find("img[rel=before]").attr("height"));
// Convert the images into background images on layered divs
$(this).append("<div class='after'></div>").find(".after").css({"background": "url(" + $(this).find("img[rel=after]").attr("src") + ")", "width": $(this).find("img[rel=after]").attr("width") + "px", "height": $(this).find("img[rel=after]").attr("height") + "px"});
$(this).append("<div class='before'></div>").find(".before").css({"background": "url(" + $(this).find("img[rel=before]").attr("src") + ")", "width": $(this).find("img[rel=before]").attr("width") - 40 + "px", "height": $(this).find("img[rel=before]").attr("height") + "px"});
// Add a helpful message
$(this).append("<div class='help'>Beweeg over de foto om voor/na te zien</div>");
// Remove the original images
$(this).find("img").remove();
// Event handler for the mouse moving over the image
$(this).mousemove(function(event){
// Need to know the X position of the parent as people may have their browsers set to any width
var offset = $(this).offset().left;
// Don't let the reveal go any further than 50 pixels less than the width of the image
// or 50 pixels on the left hand side
if ((event.clientX - offset) < ($(this).find(".after").width() -30) && (event.clientX - offset) > 30) {
// Adjust the width of the top image to match the cursor position
$(this).find(".before").width(event.clientX - offset);
}
});
// Fade out the help message after the first hover
$(this).hover(function(){
$(this).find(".help").animate({"opacity": 0}, 400, function(){ $(this).find(".help").remove(); });
});
});
});
</script>
<style type="text/css" media="screen">
.beforeafter { position: relative; overflow: hidden; }
.before, .after { position: absolute; top: 0; left: 0; }
.before {
border-right: 1px solid white;
-moz-box-shadow: 1px 0 20px #222;
-webkit-box-shadow: 1px 0 20px #222;
box-shadow: 1px 0 20px #222;
}
.help {
position: absolute;
bottom: 20px;
right: 70px;
font: bold 20px/1em Helvetica, Arial, sans-serif;
color: #FFF;
opacity: 0.7;
}
</style>
</head>
<body>
<div class="beforeafter">
<img src="ward.jpg" rel="before" alt="" width="640" height="480" />
<img src="christian.jpg" rel="after" alt="" width="640" height="480" />
</div>
</body>
</html>