如果用户将光标移动到块#鼠标指针之外,它将在菜单和其他div下消失。我想让图像只跟随光标时,它是在块内的id #鼠标指针。
$(function (){
$(window).mousemove(function(event) {
$('#mouse-pointer').css({
'top' : event.pageY -100 + 'px',
'left' : event.pageX -100 + 'px'
});
});
});html
<style>
#my-container{
position: relative;
width:100vw;
height: 600px;
overflow-x: hidden !important;
overflow-y: hidden !important;
cursor: none;
}
</style>
<div id="my-container">
<div id="lg-top-image" data-src="img/image_above.jpg"></div>
<div id="lg-bottom-image" data-src="img/image_below.jpg"></div>
<figure id="mouse-pointer"></figure>
</div>发布于 2016-02-19 22:16:07
如果您希望事件仅从某个元素触发,则不应在窗口上添加事件侦听器。改为执行以下操作:
$('#my-container').on('mousemove', function() {
$('#mouse-pointer').css({
'top' : event.pageY -100 + 'px',
'left' : event.pageX -100 + 'px'
});
});https://stackoverflow.com/questions/35507016
复制相似问题