如何向jquery事件添加函数

how can i add function to jquery event

本文关键字:添加 函数 事件 jquery      更新时间:2023-09-26

在鼠标悬停事件中,我想调用一个函数,当鼠标悬停在图像上时,它会做一些事情,但我不知道如何为它编写代码。

function reload(){
 $("img.lazy").lazyload({
            effect : "fadeIn",
            event:"mouseover"
           });
}

例如:-

function reload(){
 $("img.lazy").lazyload({
            effect : "fadeIn",
            event:function(moueover)
            {
            //do somthing here
            }
           });
     }

您想要使用mouseenter:

$('.test').on('mouseenter', function() {
  alert( 'mouse is over here' );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="test">Hover here</div>

让我们看看这是否适用于

$(function() {
    $("img.lazy")
        .mouseover(function() { 
            console.log("Mouseover");
        });
});

你可以喜欢这个

            jQuery('#youdomid').hover(function(){
                // do your stuff here
              //, your mouse has entered
              alert(2);
            },
            function (){
            // your mose leave the element
               // do the stuff what you want
               alert("leaved");
               }
            )

您也可以使用.hoverver函数

$( "img.lazy" ).hover(function() {
$( this ).fadeOut( 100 );
$( this ).fadeIn( 500 );
});
$(document).ready(function(){
    $("img.lazy").lazyload({effect : "fadeIn"}, function() {
         mousehover();
    });
}
function mousehover(){
     //do something mousehover stuff on here
}

您只需使用下面的事件mouseenter

$('.lazy').on('mouseenter', function() {
    console.log('foo');
});