简体   繁体   English

游标的错觉

[英]Illusion of moving Cursor

Is it possible to make an image appear at cursor location (for example, a cursor image) then hide the original ( cursor:none; ) then make the image move! 是否可以使图像出现在光标位置(例如,光标图像),然后隐藏原始图像( cursor:none; ),然后使图像移动! Giving the illusion that the pointer is moving by itself, then making the cursor appear where the image of the cursor went. 给人一种幻象,即指示器自身在移动,然后使光标出现在光标图像所在的位置。 Then make the image disappear. 然后使图像消失。 I'm not sure about making the cursor appear 我不确定要显示光标

I read that it is impossible to move the cursor with Javascript for security reasons, so I was thinking of just creating the illusion of it wich is fine for my purposes. 我读到,出于安全原因,无法使用Javascript移动光标,因此我考虑仅出于其目的创建一种幻觉就可以了。 An yes or no will suffice! 是或否就足够了! (so i can go foward) Didn't find much about making images appear at cursor location! (这样我就可以向前走了)关于使图像显示在光标位置上并没有太多发现! :P :P

An yes or no will suffice!

Yes

Okay, so let's answer a bit more in-depth... 好吧,让我们更深入地回答...

We make a div ( #bar ) where we want the "custom" pointer to be in and on which we'll hide the actual pointer: 我们在div( #bar )中放置“自定义”指针,并在其中隐藏实际指针:

<div id="bar">
    <div id="pointer"></div>
</div>

Set cursor to none to hide the actual pointer, set up an image in #pointer to act as substitute: cursor设置为none可以隐藏实际的指针,在#pointer设置一个图像以替代它:

body {
    padding:50px;
}
#bar {
    background-color: green;
    width: 400px;
    height: 400px;
    cursor: none;
}
#pointer {
    position: absolute;
    width:32px;
    height:32px;
    background-image:url('//i.imgur.com/uKc3VMy.png');
}

Add a little javascript (I took the jQuery route, but it's perfectly possible using vanilla JS as well) to move the image around acting as pointer: 添加一些JavaScript(我采用了jQuery路线,但是使用香草JS也完全可以实现)来移动图像作为指针:

$("#bar").mousemove(function (e) {
    $('#pointer').offset({
        left: e.pageX,
        top: e.pageY
    })
});

Sample: http://jsfiddle.net/e9BXg/1/ 样本: http//jsfiddle.net/e9BXg/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM