wainzor,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.modal1,
.modal2 {
display: none;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(function() {
const $elem = $(".gifka"),
modal = $('.modal1, .modal2').toArray();
$elem.on('click', () => {
let [a, b] = modal;
$(a).fadeIn();
$(b).fadeOut();
modal.reverse()
});
});
</script>
</head>
<body>
<img src="https://javascript.ru/forum/images/smilies/smile.gif" alt="" class="gifka">
<div class="modal1">modal1</div>
<div class="modal2">modal2</div>
</body>
</html>