First, you need to save a link to the image that is currently displayed.
curImg = $('.modal-content img').attr('src', $(this).find('img').attr('src'));
Further, in the button handlers, use fadeOut on this picture, passing the callback function in which to switch to a new picture and do fadeIn back, for example:
curImg.fadeOut(function() { imageClicked.next().find('img').trigger('click'); curImg.fadeIn(); });
Edited jsfiddle
jQuery(document).ready(function($) { var imageClicked, curImg; $(".gallery li").click(function() { $(".modal-content").fadeIn(); curImg = $('.modal-content img').attr('src', $(this).find('img').attr('src')); imageClicked = $(this); }); $(".modal-close").click(function() { $(".modal-content").fadeOut(); }); $('.btnModal-right').click(function() { curImg.fadeOut(function() { imageClicked.next().find('img').trigger('click'); curImg.fadeIn(); }); }); $('.btnModal-left').click(function() { curImg.fadeOut(function() { imageClicked.prev().find('img').trigger('click'); curImg.fadeIn(); }); }); });
ul.gallery { position: relative; display: block; width: 100%; } .gallery li { display: inline-block; position: relative; width: 100px; height: 100px; } .gallery li img { display: block; position: relative; width: 100px; height: 70px; } .modal-content { background-color: white; display: none; padding: 10px 10px 20px 10px; position: fixed; z-index: 1000; height: 350px; width: 500px; } .btnModal-left, .btnModal-right { display: inline-block; border: 1px solid black; } .modal-content img { display: block; position: relative; max-height: 350px; max-width: 500px; } .modal-close { position: absolute; z-index: 9999; right: 15px; top: 15px; width: 40px; height: 20px; display: block; overflow: hidden; border: 1px solid black; opacity: 1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="content"> <div class="modal-content"> <div class="modal-close">Close</div> <div class="btnModal-left">Prev</div> <!--end btnLeft--> <div class="btnModal-right">Next</div> <!--end btnRight--> <img src="http://o.aolcdn.com/hss/storage/adam/5d7b5eedccc289bd332af80a1ad5a226/montero-2017-us.jpg"> <br> </div> </div> <!--.modal-content--> <ul class="gallery"> <li> <img src="http://o.aolcdn.com/hss/storage/adam/a1289c4c6916baabb98e4673c7052f8/2014-hyundai-veloster-reflex-chicago.jpg"> </li> <li> <img src="http://o.aolcdn.com/hss/storage/adam/a039929c8405451173090144693c1fa0/vw-grc-beetle-chicago.jpg"> </li> <li> <img src="http://o.aolcdn.com/dims-shared/dims3/GLOB/crop/1280x850+0+0/resize/628x417!/format/jpg/quality/85/http://o.aolcdn.com/hss/storage/adam/1799bb1e072b82bda13c81563bdf5d0f/01-lingenfelter-reaper-chicago-1.jpg"> </li> </ul>