-2

I want to write function which will show div with video at specific hour every day and hide it after 10 minutes.

Something similiar was here, but it doesn't solve my problem: Show and hide divs at a specific time interval using jQuery

Pleae help

Community
  • 1
  • 1
reaker
  • 1

2 Answers2

0

You get the date with new Date() then user getHours and getMinutes if it's 20 you show your div and set a TimeOut calling hideDiv in 600 000ms (10min). Didn't tried. But here how it could look like. It's possible that the hours return are in AM/PM system so make a bit of research.

var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();

if ((hours == 20) && (minutes == 0)){
   ShowDiv();
   setTimeout(function(){
        Hidediv();
    },600 000);
}

ShowDiv(){
  $('.YourDivClassName').css('display','inline');
}
HideDive(){
$('.YourDivClassName').css('display','none');
}
user28470
  • 419
  • 5
  • 17
0

http://jsfiddle.net/quoxnmv1/10/

Do something like this, replace .style.display with fadeIn in jQuery

heureExec = '10';
minExec = '25';
timeOut = '10';
setInterval(function(){

    var date = new Date();
    var heure = date.getHours().toString();
    var minutes = date.getMinutes().toString();

    if(heure == heureExec && minutes == minExec){
        if(document.getElementById('video').style.display == 'none'){
             document.getElementById('video').style.display = 'block';        
        }
    }

    var end = parseInt(minExec)  + parseInt(timeOut);
    end = end.toString();
    if(heure == heureExec && minutes == end ){
        if(document.getElementById('video').style.display == 'block'){
             document.getElementById('video').style.display = 'none';        
        }
    }

},30000)
Djillian
  • 26
  • 3