0

I was planning to create the effect like when watching video (like Youtube), the mouse is not moving for few second the bottom bar and cursor will automatically hidden, if moving mouse again cursor and bar will show automatically. Any suggestion do do that ? Thanks

var countdown;

$(".stage").hover(function() {
  $(".bar").fadeIn();
  clearTimeout(countdown);
});
countdown = setTimeout(function() {
  $(".bar").fadeOut();
}, 5000);

 $(".stage").hover(
  function(e){ $(".bar").fadeIn(); }, // over
  function(e){ $(".bar").fadeOut();

  }  // out
 );
.stage{
  height:400px;
  width:auto;
  background:#ccc;
  }
.bar{
  height:20px;
  width:auto;
  background:#000;
  display:none;
  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="stage">
  <div class="bar"></div>
</div>
Amal Dev
  • 1,938
  • 1
  • 14
  • 26
FeelRightz
  • 2,777
  • 2
  • 38
  • 73

4 Answers4

2

There is a function in jQuery called .mousemove() that you can use for your purpose.

cespon
  • 5,630
  • 7
  • 33
  • 47
1

Here's an working example: http://jsfiddle.net/nnnoLkue/. You should use mousemoveto appear the .bar when it's disappear.

$(".stage").hover(function() {
  $(".bar").fadeIn();
    fadeOutBar();
}, function(e){
    $(".bar").fadeOut();
});
$('.stage').mousemove(function() {
    $(".bar").fadeIn();
    fadeOutBar();
});
function fadeOutBar() {
    setTimeout(function() {
      $(".bar").fadeOut();
    }, 2000);
}
Radonirina Maminiaina
  • 6,958
  • 4
  • 33
  • 60
0
time = 0;

time = setInterval(function(){
    //hide bar if he counts to 5 sec
    $(".bar").fadeOut();
},5000);

$('#video').mousemove(function(){
    clearInterval(time);
    //show bar
    $(".bar").fadeIn();
});
Vinc199789
  • 1,046
  • 1
  • 10
  • 31
0

If you want to delete the old hover and re hover element hide first the .bar

$('.stage').mousemove(function() {
   $(".bar").hide();
   $(".bar").fadeIn();
});
Smar ts
  • 49
  • 5