Changing the css of a div with Jquery mouseover

1

I need that, if the mouse is not on top of a div, after 4 seconds it disappears, changing the css. How to do this with Javascript / Jquery?

    
asked by anonymous 15.04.2016 / 02:14

1 answer

3

CSS:

.hide{
    display: none;
);

HTML:

<div id="my-div" style="background-color:#ff0000" >Minha Div</button>

JavaScript:

function hideDiv(){
    $("#my-div").addClass('hide');
}

t = setTimeout(hideDiv,4000);

$("#my-div").mouseout(function(event){
    t = setTimeout(hideDiv,4000);
});

$("#my-div").mouseover(function(){

    if (t!=null) {
        clearTimeout(t);
    }
});
    
15.04.2016 / 04:58