![](/img/trans.png)
[英]How to replace the default mouse scroll behavior by moving to each div tag each time the mouse scrolls up or down?
[英]How to attach div to cursor each time window scrolls
几个月前我刚开始编程,我对这门语言很陌生。 我想制作一个定制的 cursor,我发现这段代码运行良好。 唯一的问题是,当滚动自定义 cursor 时,它会粘在背景上并随着正文滚动。 它看起来不自然,因为它应该固定在适当的位置。 我在这里想念什么? 谢谢
$( document ).ready(function() {
//attach div to cursor each time mouse moves
$(document).mousemove(function(e){
$(".custom-cursor").css({left:e.pageX, top:e.pageY});
});
//attempt to attach div to cursor each time window scrolls
$(document).on('scroll', function(e){
$(".custom-cursor").css({left:e.pageX, top:e.pageY});
});
//change cursor over menu
$('body a').mouseleave(function() {
$('.custom-cursor').removeClass('activemenu');
});
});
将您的 cursor div 设置为position: fixed
应该可以解决问题。
编辑:正如另一位用户评论的那样, cursor: url(custom.cur),auto;
显然是更好的解决方案。 否则你会做很多不必要的 js 操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.