Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.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 jQuery-是否可以向前悬停到另一个元素?_Javascript_Jquery_Html_Hover - Fatal编程技术网

Javascript jQuery-是否可以向前悬停到另一个元素?

Javascript jQuery-是否可以向前悬停到另一个元素?,javascript,jquery,html,hover,Javascript,Jquery,Html,Hover,我终于有了一部奇特的动画作品。这是一个悬停事件,触发动画,我想有一个更大的是涵盖了该悬停。当我简单地将鼠标悬停应用于父div时,它会给我带来一大堆新问题,所以这对我来说是不可能的 相反,我在想是否可能将悬停事件转发给子元素 JS: $('canvas').hover( ... functions ... ) 在这个小小的画布区域,一切都完美无瑕 HTML: <div class="parent"> -> somewhere here is the <

我终于有了一部奇特的动画作品。这是一个悬停事件,触发动画,我想有一个更大的是涵盖了该悬停。当我简单地将鼠标悬停应用于父div时,它会给我带来一大堆新问题,所以这对我来说是不可能的

相反,我在想是否可能将悬停事件转发给子元素

JS:

$('canvas').hover(  ... functions ... ) 
在这个小小的画布区域,一切都完美无瑕

HTML:

<div class="parent">
      -> somewhere here is the <canvas> embedded
</div>
HTML:
->这里的某个地方是嵌入式的
因此,每次我悬停
时,我都希望
触发悬停事件

但是要注意:有三列具有三倍于相同结构,因此每个
应该只触发包含

我希望你明白我的意思,我不是在说完全的公牛***

你可以使用触发器:

 $('canvas').trigger('hover');
然后附上:

$('canvas'.on('hover',function(){
//do something
})
或者简单地说

$('canvas').trigger('hover',function(){
//do something
});

当鼠标悬停在父俯冲时,必须将类添加到画布“活动”中,当鼠标悬停时,必须删除类“活动”

<script>
   $(".parent").on('mouseover',function(){
      $(this).find( "canvas" ).addClass('active');
   }) .mouseout(function() {
      $(this).find( "canvas" ).removeClass('active');
   });
</script>

$(“.parent”).on('mouseover',function(){
$(this.find(“canvas”).addClass(“active”);
}).mouseout(函数(){
$(this.find(“canvas”).removeClass(“active”);
});
演示:


它应该可以工作,试试看。

是的,您可以使用Jquery轻松完成:

$('.parent').hover(function(){
  $(this).find('canvas').trigger('hover');
);
.hover()方法绑定mouseenter和mouseleave事件的处理程序。您可以使用它在鼠标位于元素内期间简单地将行为应用于元素

$('.parent').on('mousenter mouseleave', function(e) {
    $(this).find('canvas').trigger('hover');
});
它将为画布应用与mouseenter和mouseleave的父级相同的触发器

所以

canvas
悬停事件与父对象绑定
mousenter

 $('.parent').on('mousenter', function(e) {
     $(this).find('canvas').trigger('hover');
 });
使用父级
mouseleave
属性解除绑定
canvas
悬停事件

$('.parent').on('mouseleave', function(e) {
     $(this).find('canvas').hover(over, out);
});

不看为什么????尝试
$('.parent').hover(函数(e){$(this.find('canvas')).trigger(e.type);})查看此操作:
$('.parent').on('mouseleave', function(e) {
     $(this).find('canvas').hover(over, out);
});