我几个月前才开始编程,我对这种语言非常陌生。我想做一个自定义游标,我发现这段代码工作得很好。唯一的问题是,当滚动自定义光标时,它会粘住背景,并与身体一起滚动。它看起来不自然,因为它应该坚持在适当的地方。我在这里错过了什么?谢谢
$( 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');
});});
发布于 2020-05-31 22:08:55
将光标div设置为position: fixed应该可以做到这一点。
编辑:正如另一个用户所评论的,cursor: url(custom.cur),auto;显然是更好的解决方案。否则,您将执行许多不必要的js操作。
https://stackoverflow.com/questions/62123039
复制相似问题