![](/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.