-
Notifications
You must be signed in to change notification settings - Fork 0
/
image-switcher.js
25 lines (24 loc) · 997 Bytes
/
image-switcher.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
(function() {
var action = document.getElementById("image-switcher-action");
if(action){
action.addEventListener("click", function(event) {
var animation = $(action).hasClass('image-switch-animation');
switchImage(animation);
});
function switchImage(animation) {
$(".image-switcher").each(function( index ) {
let xSrc = $(this).data("switch-src");
let ySrc = this.src;
$(this).attr("src", xSrc);
$(this).data("switch-src", ySrc);
if(animation === true){
let animationType = $(this).data('animation');
this.classList.add('animate__animated', 'animate__'+animationType);
this.addEventListener('animationend', () => {
this.classList.remove('animate__animated', 'animate__'+animationType);
});
}
});
}
}
})();