This question is kind of a duplicate, but I have read through all the other answers, but none of them were helpful. I have an image where I want to zoom in on and be able to move with the mouse. Like the banner image on this website. https://www2.hotelspro.com/.
This is the code for my image
<img src="https://via.placeholder.com/500" class="flickity-viewport">
I have a jQuery script that does the mouse movement and that works fine. Here is the code.
<script>
jQuery(document).ready(function($){
var lFollowX = 0,
lFollowY = 0,
x = 0,
y = 0,
friction = 1 / 10;
function moveBackground() {
x += (lFollowX - x) * friction;
y += (lFollowY - y) * friction;
translate = 'translate(' + x + 'px, ' + y + 'px) scale(1)';
$('.flickity-viewport').css({
'-webit-transform': translate,
'-moz-transform': translate,
'transform': translate
});
window.requestAnimationFrame(moveBackground);
}
$(window).on('mousemove click', function(e) {
var lMouseX = Math.max(-100, Math.min(100, $(window).width() / 2 -
e.clientX));
var lMouseY = Math.max(-100, Math.min(100, $(window).height() / 2 -
e.clientY));
lFollowX = (20 * lMouseX) / 100; // 100 : 12 = lMouxeX : lFollow
lFollowY = (10 * lMouseY) / 100;
});
moveBackground();
});
</script>
Here is the CSS that works fine on itself, but not with the jQuery
.flickity-viewport{
transition: transform .2s ease-in-out;
}
.flickity-viewport:hover{
transform: scale(1.2);
}
I have tried !important and all the answers I have found here, but nothing works. Hope someone can help me :)
This is the Codepen that explains what I am talking about. I want to scale the image by a number and be able to move it around like that. https://codepen.io/BilendM/pen/WBLmad