簡體   English   中英

每次 window 滾動時,如何將 div 附加到 cursor

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM