TheKraven
TheKraven

Reputation: 583

Stopping hover function with a click function

        $("#theDiv").hover(function(){
            $(this).animate( {top: "300px", left: "400px", width: "50px" , height: "50px" },"Fast")
        }); 

        $("#theDiv").click(function(){
            $(this).stop();
        }); 

Code as above. I tried to stop the hover function when I click it, but it doesn't work. Or is it not possible at all ?

Upvotes: 0

Views: 54

Answers (2)

Alex
Alex

Reputation: 35399

$("#theDiv").mouseenter(function(){
    $(this).animate( {
        top: "300px",
        left: "400px",
        width: "50px" ,
        height: "50px"
    } , "fast");
}).click(function(){
    $(this).stop(true, false);
});

.stop( [clearQueue] [, jumpToEnd] )

Upvotes: 1

adeneo
adeneo

Reputation: 318172

$("#theDiv").on({
    mouseenter: function() {
        $(this).animate( {top: "300px", left: "400px", width: "50px" , height: "50px" },"Fast");
    },
    click: function() {
        $(this).off('mouseenter').stop(true);
    }
});

FIDDLE

Upvotes: 0

Related Questions