簡體   English   中英

我如何添加功能到jQuery事件

[英]how can i add function to jquery event

在mouseover事件上,我想調用函數,該函數會在鼠標懸停在圖像上時執行somethig,但我不知道如何為其編寫代碼。

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");
               }
            )

您還可以使用.hover函數

$( "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');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM