Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在其他元素上单击“使用元素”_Javascript_Jquery_Leap Motion - Fatal编程技术网

Javascript 在其他元素上单击“使用元素”

Javascript 在其他元素上单击“使用元素”,javascript,jquery,leap-motion,Javascript,Jquery,Leap Motion,我知道这听起来很傻,但我想做的是在某个html元素悬停在另一个元素上时触发单击 假设我们得到了悬停在锚文本上的.cursor。在这种情况下,点击。光标应该会打开一个谷歌页面 <div class="cursor"></div> <div class="htmlPage"> <a href="www.google.com">Google</a> <a href="www.facebook.com">Facce

我知道这听起来很傻,但我想做的是在某个html元素悬停在另一个元素上时触发单击

假设我们得到了悬停在锚文本上的.cursor。在这种情况下,点击。光标应该会打开一个谷歌页面

<div class="cursor"></div> 
<div class="htmlPage">
    <a href="www.google.com">Google</a>
    <a href="www.facebook.com">Faccebook</a>
     <a href="www.stackoverflow.com">Stack</a>
</div> 
光标应该是可移动的,应该能够点击其他链接

光标就是那个盘旋在谷歌按钮上的蓝色圆圈。 这里我把光标放在谷歌上,现在点击这个链接就可以链接到谷歌了,若我要点击堆栈,那个么堆栈应该已经打开了

试试这个:

试试这个:


将事件处理程序附加到游标类

$('.cursor').on('click',function()
{
    window.location.href = $(this).siblings('.htmlPage').attr('href');
}

这将获取元素的同级,并使位置等于该同级

将事件处理程序附加到游标类

$('.cursor').on('click',function()
{
    window.location.href = $(this).siblings('.htmlPage').attr('href');
}

这将获取元素的同级,并使位置等于该同级。要更明确一点,这可能是最好的

$('.cursor').click(function(){
  $(this).next().children('a').click();
});

更明确一点,这可能是最好的

$('.cursor').click(function(){
  $(this).next().children('a').click();
});
您可以尝试在单击时获取“.cursor”位置,并与每个“.htmlPage a”位置进行比较,然后使用重叠的元素之一更改window.location.href

$(".cursor").click(function(){
    var cursor=$(this);
    var cl = cursor.offset().left;
    var cr = cl+cursor.width();
    var ct = cursor.offset().top;
    var cb = ct+cursor.height();
    $(".htmlPage a").each(function(){
        var page=$(this);
        var pl = page.offset().left;
        var pr = pl+page.width();
        var pt = page.offset().top;
        var pb = pt+page.height();
        if(((cl>pl&&cl<pr)||(cr>pl&&cr<pr))&&((ct>pt&&ct<pb)||(cb>pt&&cb<pb))){
            window.location.href=page.attr("href");
        }        
    });
}).draggable();    
$(“.cursor”)。单击(函数(){
var cursor=$(这个);
var cl=cursor.offset().left;
var cr=cl+cursor.width();
var ct=cursor.offset().top;
var cb=ct+cursor.height();
$(“.htmlPage a”).each(函数(){
变量页=$(此);
var pl=page.offset().left;
var pr=pl+page.width();
var pt=page.offset().top;
var pb=pt+page.height();
如果((cl>pl&&clpl&&crpt&&ctpt&&cb您可以尝试在单击时获取“.cursor”位置,并与每个“.htmlPage a”位置进行比较,然后将window.location.href更改为重叠的元素之一

$(".cursor").click(function(){
    var cursor=$(this);
    var cl = cursor.offset().left;
    var cr = cl+cursor.width();
    var ct = cursor.offset().top;
    var cb = ct+cursor.height();
    $(".htmlPage a").each(function(){
        var page=$(this);
        var pl = page.offset().left;
        var pr = pl+page.width();
        var pt = page.offset().top;
        var pb = pt+page.height();
        if(((cl>pl&&cl<pr)||(cr>pl&&cr<pr))&&((ct>pt&&ct<pb)||(cb>pt&&cb<pb))){
            window.location.href=page.attr("href");
        }        
    });
}).draggable();    
$(“.cursor”)。单击(函数(){
var cursor=$(这个);
var cl=cursor.offset().left;
var cr=cl+cursor.width();
var ct=cursor.offset().top;
var cb=ct+cursor.height();
$(“.htmlPage a”).each(函数(){
变量页=$(此);
var pl=page.offset().left;
var pr=pl+page.width();
var pt=page.offset().top;
var pb=pt+page.height();

如果((cl>pl&&clpl&&crpt&&ctpt&&cb如果您不使用IE,您可以在CSS中使用
指针事件:none
。那么您的元素将对任何鼠标交互没有响应(并且像幽灵前景元素一样)

IE的解决方法如下:

var x = event.pageX;
var y = event.pageY;
$('.cursor').hide();
var here = document.elementFromPoint(x, y);
$('.cursor').show();
// Do what you want with the element here
// Find the parent a element needed with here.parentNode and here.tagName === "A"
// And then fire the click function
我从未使用过jQuery,但我认为它应该可以工作


希望它能帮助你

如果你不使用IE,你可以在CSS中使用
指针事件:none
。那么你的元素将对任何鼠标交互没有反应(并且像幽灵前景元素一样)

IE的解决方法如下:

var x = event.pageX;
var y = event.pageY;
$('.cursor').hide();
var here = document.elementFromPoint(x, y);
$('.cursor').show();
// Do what you want with the element here
// Find the parent a element needed with here.parentNode and here.tagName === "A"
// And then fire the click function
我从未使用过jQuery,但我认为它应该可以工作



希望它能有所帮助

你所说的
光标应该是可移动的,并且应该能够点击其他链接是什么意思
?光标应该是可移动的,没有任何限制。我只是添加了一张图片,可以解释更多。我明白了,我已经更新了我的答案。你说的
光标应该是可移动的,应该能够点击是什么意思其他链接
?光标将是可移动的,没有任何限制。我只是添加了一张图片,可以解释更多内容。我知道了,我已经更新了我的答案。这里最大的问题是你不能访问所有链接。你不能触发下面的元素(下)光标。我明白了…希望这个演示会有帮助。只有一个光标。这是如何移动的?用户是在拖动它吗?还是它只是跟随光标?它的跳跃运动是受控的。但是你可以把它看作是被拖动的。这里最大的问题是你不能访问所有的链接。你不能触发下面(下)的元素光标。我明白了…希望这个演示会有帮助只有一个光标。这是如何移动的?用户是在拖动它吗?还是它只是跟随光标?它的跳跃运动是受控的。但是你可以把它看作是被拖动的。我想你甚至可以直接向here元素启动onclick函数,就像它会向a元素冒泡一样。我要回答我的问题我自己的问题。这里最好的技巧是你得到一个对象,你可以触发点击和所有其他鼠标效果。我认为你甚至可以直接对here元素启动onclick函数,因为它会对a元素产生气泡。我将用这个来回答我自己的问题。这里最好的技巧是你得到对象,然后你可以触发点击以及所有其他鼠标效果。