同じクラス名で複数のdivにmousemoveを実行したいが、マウスの位置は各div内で再開されない。ここ同じクラス名を持つ複数のdivのmousemove
はここdemo
である私のコードです:
<body>
<div class="reference" id="landing-content" style="background-image: url(http://www.samsung.com/fr/consumer/mobile-devices/smartphones/galaxy-s/galaxy-s7/gear-360/images/gear-360_slide360_02.jpg);"><section class="slider"></section></div>
<div class="reference" id="landing-content" style="background-image: url(http://www.samsung.com/fr/consumer/mobile-devices/smartphones/galaxy-s/galaxy-s7/gear-360/images/gear-360_slide360_01.jpg);"><section class="slider"></section></div>
<div class="reference" id="landing-content3"><section class="slider"></section></div>
<div class="reference" id="landing-content4"><section class="slider"></section></div>
<div class="reference" id="landing-content5"><section class="slider"></section></div>
<div class="reference" id="landing-content6"><section class="slider"></section></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</body>
$(document).ready(function(){
$('.reference').mousemove(function(e){
var x = -(e.pageX + this.offsetLeft)/1.15;
var y = -(e.pageY + this.offsetTop)/1.15;
$(this).css('background-position', x + 'px ' + y + 'px');
$(this).css('transition', 'background-position 1.5s ease-out');
});
});