Below I tried to create a Javascript code as per requirement that
If the arrival time of train is at "4:30" , text should start blink before two minutes of arrival time i.e., at "4:28"
and should continue blinking after the two minutes of departure time.
i.e., If departure time of train is "4:35" , text should continue blink till
"4:37" (starting from "4:28") :-
<script>
var t = <%= this.time%>; // getting current time of system
var a = <%=this.arrival%>; //getting arrival time
var d = <%=this.departure%>; //getting departure time
var id = setInterval(function () {
var startTime = new Date(t); //getting current time
var endTime = new Date(a); //pass the arrival time of train
var difference = endTime.getTime() - startTime.getTime(); // This will give difference in milliseconds
var resultInMinutes = Math.round(difference / 60000);
startTime = new Date(t); //getting current time
endTime = new Date(d); //pass the departure time of train
difference = endTime.getTime() - startTime.getTime(); // This will give difference in milliseconds
var dipartureInMinutes = Math.round(difference / 60000);
if ((resultInMinutes <= 2) && (dipartureInMinutes >= -2)) //if difference is less than 2 minutes
{
//code to highlight the section
//alert("blink starts..!!");
obj = document.getElementsByTagName("BLINK");
for (var i = 0; i < obj.length; i++) {
if (obj[i].className == "blk") {
if (obj[i].style.visibility == "hidden") {
obj[i].style.visibility = "visible";
obj[i].style.color = "red";
} else {
obj[i].style.visibility = "hidden";
}
}
}
}
else {
clearInterval(id); //code to kill set interval
}
}, 500);
</script>
HTML code:
<blink class="blk">Attention Please!!</blink><br /><br />Train is about to come after x minutes...
But its not working please help me to solve it as per requirement.
Please reply. Im stuck in it from long time.