如何在屏幕上设置光标位置? [英] How to set the cursor position on the screen?
问题描述
当页面加载时,有没有任何方法可以设置光标位置离开屏幕/网页或页面的顶部/底部?如果是这样,我如何可以定位它,也许使用javascript,jquery或php?感谢!
Is there any way I can set the cursor position off the screen/webpage or on top/bottom of the page when a page is load? If so how can I target it, maybe using javascript, jquery or php? Thanks!
推荐答案
此响应基于用户需要避免在加载时与网页互动。
首先,我们需要创建停靠点。为此,我们将使用pageLayover的ID。
First, we'll need to create the layover. For this, we're going to use an ID of 'pageLayover'.
我们的CSS:
#pageLayover{
position:absolute;
top:0;
left:0;
width:100%;
height:100%;
background:transparent;
z-index:9000;
display:block;
}
然后我们的jQuery:
Then our jQuery:
$(function(){
$("body").append('<div id="pageLayover"></div>');
$(document).mousemove(function(){ //capture mouse movement event
$("#pageLayover").remove(); // remove our layover from the DOM
});
});
这是基础知识。你可以从那里调整。几个用户不断使用他们的鼠标,因此您可能要延迟使用该功能,直到页面加载几秒钟后。
That's the basics. You can tweak with it from there. Several users are constantly using their mouse so you may want to delay the use of the function until after a few seconds of the page load.
祝你好运。
编辑以提供更好的解决方案可见性
我同意MyStream这里,这绝对不是有限解。正如我在注释中指出的那样,需要进行调整。
I agree with MyStream here, This is definitely not a finite solution. There's tweaking to be done, as I noted in the comment.
如果你希望这也是一个点击功能,你只需要使它成为一个点击功能。
If you want this to also be a click function, you simply need to make it a click function.
$("#myClickElement").live('click', function(){
$("body").append('<div id="pageLayover"></div>');
});
将追加页面。如果要将删除的范围移动到一个点击,可以使用规范化的mousedown函数,例如 - >
will append the pagelayover. If you want to move the scope of the remove to a click, you could use the normalized mousedown function, such as ->
$('#element').mousedown(function(event) {
if(event.which == 1){ $("#pageLayover").remove();
});
这篇关于如何在屏幕上设置光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!