-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathntSliderZoom.js
71 lines (57 loc) · 1.92 KB
/
ntSliderZoom.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
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
Template.body.events({
'click .nt-slider-zoom .nt-photo': function (event, template) {
//Get the img, container and content
var $img = $(event.currentTarget).find('img');
var $container = $(event.currentTarget).parents('.nt-slider');
var $content = $(event.currentTarget).parents('.nt-content');
//Scroll up
var offsetTop = $container[0].offsetTop;
$content.animate({scrollTop: offsetTop }, 200);
//Check if it's already enlarged
if ($img.hasClass('nt-enlarged')) {
//Return to normal
$img.velocity({
width: $img.data('originalWidth'),
height: $img.data('originalHeight')
}, { duration: 200 });
//Toggle the enlarged class
$img.removeClass('nt-enlarged');
} else {
//Reduce any other enlarged images
var $enlarged = $container.find('.nt-enlarged');
$enlarged.velocity({
width: $enlarged.data('originalWidth'),
height: $enlarged.data('originalHeight')
}, {
duration: 200,
complete: function() {
$(this).removeClass('nt-enlarged');
}
});
//$enlarged.css('width', $enlarged.data('originalWidth'));
//$enlarged.css('height', $enlarged.data('originalHeight'));
//Save the original sizes
$img.data('originalWidth', $img.width());
$img.data('originalHeight', $img.height());
//Calculate the bigger size (100% of the viewport)
var ratio = $(window).width() / $img.width();
var newWidth = $(window).width() + 'px';
var newHeight = ( $img.height() * ratio ) + 'px';
//Animate
$img.velocity({
width: newWidth,
height: newHeight
}, {
duration: 200,
complete: function() {
var offsetLeft = event.currentTarget.offsetLeft;
$container.animate({scrollLeft: offsetLeft }, 200);
$img.addClass('nt-enlarged');
}
});
// //Scroll into place
// Meteor.setTimeout(function() {
// }, 500);
}
}
});