Good day everyone!
In general, I want to make a slider, like on Amazon, not even the slider itself, but the opportunity to enlarge the photo and when you move the mouse over the picture, it moves (so that you can see the details)
My attempt failed, here's the HTML code:
<div class="main"> <div id="carousel" class="slider"> <div data-thumb="https://allstringsnylon.com/media/catalog/product/cache/1/image/17f82f742ffe127f42dca9de82fb58b1/c/o/cordoba-15cm-concert-uke-top_lrg_1.png"><img src="https://allstringsnylon.com/media/catalog/product/cache/1/image/17f82f742ffe127f42dca9de82fb58b1/c/o/cordoba-15cm-concert-uke-top_lrg_1.png" alt=""></div> <div data-thumb="http://rolandblog.ca/wp-content/uploads/2013/11/13082_MATON-UKULELE-CEDAR-TOP__98800_zoom.jpg"><img src="http://rolandblog.ca/wp-content/uploads/2013/11/13082_MATON-UKULELE-CEDAR-TOP__98800_zoom.jpg" alt=""></div> <div data-thumb="http://www.lunaguitars.com/productimages/uketribal6/uketribal6.jpg"><img src="http://www.lunaguitars.com/productimages/uketribal6/uketribal6.jpg" alt=""></div> </div> </div> Js:
$(function () { $(".slider").slick({ autoplay: true, dots: true, customPaging : function(slider, i) { var thumb = $(slider.$slides[i]).data('thumb'); return '<a><img src="'+thumb+'"></a>'; }, }); var trueHeight, trueWidth, img; $('.slick-slider div img').hover(function(e){ img = $(this); trueHeight = $(this).height(); trueWidth = $(this).width(); $(this).css('position', 'absolute'); var imgHeight = $(this).prop('naturalHeight'); var imgWidth = $(this).prop('naturalWidth'); $(this).height(imgHeight); $(this).width(imgWidth); $(this).mousemove(function(e) { var relativeX = e.clientX; var relativeY = e.clientY; console.log(relativeX+ ' ' +relativeY); img.css({'left': relativeX / -6 + 'px', 'top': relativeY / -1.0 + 'px'}); }); }, function(){ img.css({'position': 'relative', 'top': 0,'left': 0}); $(this).height(trueHeight); $(this).width(trueWidth); }); }); Codepen example
It turned out not very much, everything jumps, twitches and I would like to know, maybe there are ready-made solutions? Or can someone advise how to improve my "code", can someone already did this and is ready to share! Thank!