Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.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 - Fatal编程技术网

Javascript 必须更改单击事件鼠标入鼠标出事件

Javascript 必须更改单击事件鼠标入鼠标出事件,javascript,jquery,Javascript,Jquery,下面是为点击事件编写的脚本。 我想对鼠标输入、鼠标输出事件使用相同的代码(选择器) $('.tools_collapsed').wrap('<div class="newparent" />'); var speed = 600; $('.tools_collapsed').show().css({ right: '-250px' }).hide(); $('.tools_collapsed .collapse_btn').hide(); $('.t

下面是为点击事件编写的脚本。 我想对鼠标输入、鼠标输出事件使用相同的代码(选择器)

 $('.tools_collapsed').wrap('<div class="newparent" />');
    var speed = 600;
    $('.tools_collapsed').show().css({ right: '-250px' }).hide();
    $('.tools_collapsed .collapse_btn').hide();
    $('.tools_expand').click(function () {
        $('.tools_collapsed').show().animate({ right: '0' }, { duration: speed });
        $('.tools_collapsed .collapse_btn').show();
    })
    $('a.collapsed').click(function () {
        $('.tools_expand').css({ display: 'none' });
        $('.tools_collapsed').animate({ right: '-250', easing: 'easeOutQuad' }, 400, function () {
            $('.tools_collapsed .collapse_btn').css("display", "none");
            $('.tools_expand').show("normal");
        });
    })

}
$('.tools_-collapsed').wrap('');
无功转速=600;
$('.tools_collapsed').show().css({right:'-250px'}).hide();
$('.tools_collapse.collapse_btn').hide();
$('.tools_expand')。单击(函数(){
$('.tools_collapsed').show().animate({right:'0'},{duration:speed});
$('.tools_collapse.collapse_btn').show();
})
$('a.collapsed')。单击(函数(){
$('.tools_expand').css({display:'none'});
$('.tools_collapsed')。动画({right:'-250',easeOutQuad'},400,函数(){
$('.tools\u collapsed.collapse\u btn').css(“显示”、“无”);
$('.tools_expand')。显示(“正常”);
});
})
}
试试这种方法

function yourFunction(){
   //your code here
}

$("#yourSelector").hover(
    yourFunction(), 
    yourFunction()
);
您可以尝试以下方法:

$('.tools_collapsed').wrap('<div class="newparent" />');
var speed = 600;
$('.tools_collapsed').show().css({ right: '-250px' }).hide();
$('.tools_collapsed .collapse_btn').hide();

$('.tools_expand').on( "mouseenter",function () {
    $('.tools_collapsed').show().animate({ right: '0' }, { duration: speed });
    $('.tools_collapsed .collapse_btn').show();
})

$('.tools_expand').on( "mouseout", function () {      // changed from "a.collapsed"
    $('.tools_expand').css({ display: 'none' });
    $('.tools_collapsed').animate({ right: '-250', easing: 'easeOutQuad' }, 400, function () {
        $('.tools_collapsed .collapse_btn').css("display", "none");
        $('.tools_expand').show("normal");
    });
})
$('.tools_-collapsed').wrap('');
无功转速=600;
$('.tools_collapsed').show().css({right:'-250px'}).hide();
$('.tools_collapse.collapse_btn').hide();
$('.tools_expand')。打开(“mouseenter”,函数(){
$('.tools_collapsed').show().animate({right:'0'},{duration:speed});
$('.tools_collapse.collapse_btn').show();
})
$('.tools_expand')。在(“mouseout”上,函数(){//从“a.collapsed”更改为
$('.tools_expand').css({display:'none'});
$('.tools_collapsed')。动画({right:'-250',easeOutQuad'},400,函数(){
$('.tools\u collapsed.collapse\u btn').css(“显示”、“无”);
$('.tools_expand')。显示(“正常”);
});
})

您的问题是什么?鼠标悬停和鼠标移出事件您可以将此脚本中的事件单击事件更改为鼠标悬停和鼠标伸出溢出不是免费的编码服务。告诉我们您尝试了什么以及遇到了什么问题。除非
yourFunction
返回函数,否则这是不正确的。必须将函数传递给
.hover()
。我完全同意这种方法,但正如@FelixKling所指出的,上面的语法是错误的<代码>$(“#你的选择器”)。悬停(你的函数,你的函数)。不需要
()
。您好,它工作正常,但第二次当我用鼠标进入面板时,它会自动进出。我在这里做了一些改变$('.tools_expand').hover(函数(){$('.tools_collapse').show().animate({right:'0'},{duration:speed});$('.tools_collapse.collapse_btn').show()})HTML: