Agush
Agush

Reputation: 5116

How do I animate on hover or timeout with jquery/javascript?

So I want to animate and display a menu on an element hover or when certain time has passed without a hover.

This I what I've got but it doesn't work.

var didAnimationStart = 0;

$(document).ready(function() {
    $('#logoi').hover(startAnimation()); 
    var t = setTimeout("if (didAnimationStart==0) startAnimation();",10000);
});

function startAnimation()
{
        didAnimationStart = 1;
        $('.linea').animate({
            width: "93%",
        }, 3000 );
        $('.menu-txt').animate({
            opacity: "1",
        }, 2500 );  
}

Upvotes: 1

Views: 441

Answers (1)

qwertymk
qwertymk

Reputation: 35256

Try this:

var didAnimationStart = 0;

$(document).ready(function() {
    $('#logoi').hover(startAnimation); 
    var t = setTimeout(function() { 
        if (didAnimationStart==0) startAnimation();
    },10000);
});

function startAnimation()
{
        didAnimationStart = 1;
        $('.linea').animate({
            width: "93%",
        }, 3000 );
        $('.menu-txt').animate({
            opacity: "1",
        }, 2500 );  
}

I got rid of the () in this line: $('#logoi').hover(startAnimation);

Upvotes: 2

Related Questions