• Advertisement
Sign in to follow this  

Different div/lightbox for different time of day

This topic is 2118 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys!

I've been trying to do the following:
If the time of day is between 8:30 and 17:00, the whole page is covered by red "lightbox" div. If time is between 17:00 and 18:00 the page is covered by green lightbox div. For other times there is no lightbox effect (div is not "active").
Optionaly one could "disable" the div (be it red or green) by pushing a button.

Till now I've tried several different approaches but with none of them I could "start" the div.

For lightbox I used this script:
[CODE]
<script type="text/javascript"><!--
// Content Box (Lightbox) Over Shaded Web Page
// Version 1.0a
// September 24, 2009
// Copyright 2009 Bontrager Connection, LLC
var IEmax = 2000;
var IE = (navigator.userAgent.indexOf('MSIE') != -1) ? true : false;
var xDialogBoxPosition = 0;
var yDialogBoxPosition = 0;
var ViewportHeight = 0;
var RealLength = 0;
var PageWidth = 0;
var PageHeight = 0;
var ShadowDiv;
var DialogDiv;
function GetViewportDimensions() {
var viewX = 0;
var viewY = 0;
if(self.innerWidth) {
viewX=self.innerWidth;
viewY=self.innerHeight;
}
else if(document.documentElement&&document.documentElement.clientWidth) {
viewX=document.documentElement.clientWidth;
viewY=document.documentElement.clientHeight;
}
else if(document.body) {
viewX=document.body.clientWidth;
viewY=document.body.clientHeight;
}
return Array(viewX,viewY);
} // function GetViewportDimensions()
function GetPageDimensions() {
var pageX = 0;
var pageY = 0;
if(window.innerHeight && window.scrollMaxY) {
pageX = window.innerWidth + window.scrollMaxX;
pageY = window.innerHeight + window.scrollMaxY;
}
else if(document.body.scrollHeight > document.body.offsetHeight) {
pageX = document.body.scrollWidth;
pageY = document.body.scrollHeight;
}
else if(document.body.scrollWidth && document.body.scrollHeight) {
pageX = document.body.scrollWidth;
pageY = document.body.scrollHeight;
}
else {
pageX = document.body.offsetWidth;
pageY = document.body.offsetHeight;
}
var viewDimensions = GetViewportDimensions();
if(pageX < viewDimensions[0]) { pageX = viewDimensions[0]; }
if(pageY < viewDimensions[1]) { pageY = viewDimensions[1]; }
else if(IE) {
pageY += 25;
RealLength = pageY;
ViewportHeight = viewDimensions[1];
if(pageY > IEmax) { pageY = IEmax; }
}
return Array(pageX,pageY);
} // function GetPageDimensions()
function ShadeTheWindow(shadow) {
var pageDimensions = GetPageDimensions();
PageWidth = pageDimensions[0];
PageHeight = pageDimensions[1];
ShadowDiv = document.getElementById(shadow);
ShadowDiv.style.width = PageWidth + "px";
ShadowDiv.style.height = PageHeight + "px";
ShadowDiv.style.display = "block";
} // function ShadeTheWindow();
function PositionDialogDiv() {
var xScrollPosition = window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
var yScrollPosition = window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
if(IE && PageHeight == IEmax) {
var shadowpos = ( yScrollPosition < (IEmax - ViewportHeight) ) ? 0 : yScrollPosition - 1;
if( (shadowpos + PageHeight) > RealLength ) { shadowpos = RealLength - IEmax; }
ShadowDiv.style.top = shadowpos + "px";
}
DialogDiv.style.left = xDialogBoxPosition + xScrollPosition + "px";
DialogDiv.style.top = yDialogBoxPosition + yScrollPosition + "px";
} // function PositionDialogDiv()
function DisplayDialogDiv(dialog) {
DialogDiv = document.getElementById(dialog);
if(xDialogBoxPosition == 0 && yDialogBoxPosition == 0) {
xDialogBoxPosition = parseInt(DialogDiv.style.left);
yDialogBoxPosition = parseInt(DialogDiv.style.top);
}
PositionDialogDiv();
DialogDiv.style.display = "block";
window.onscroll = PositionDialogDiv;
} // function DisplayDialogDiv()
function PresentDialogDiv(shadow,dialog) {
ShadeTheWindow(shadow);
DisplayDialogDiv(dialog);
} // function PresentDialogDiv()
function RemoveDialogDiv() {
DialogDiv.style.display = "none";
ShadowDiv.style.display = "none";
} // function RemoveDialogDiv()
//--></script>
[/CODE]

and Div's

[CODE]
<div id="shadeDivID_red"
style="
display:none;
z-index:100499;
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
margin:0;
padding:0;
border:none;
opacity:0.4;
filter:alpha(opacity=40);
background-color:#FD0006;
">
</div>
<div id="shadeDivID_green"
style="
display:none;
z-index:100499;
position:absolute;
left:0px;
top:0px;
width:100%;
height:100%;
margin:0;
padding:0;
border:none;
opacity:0.4;
filter:alpha(opacity=40);
background-color:#0F0;
">
</div>
[/CODE]


But I don't know how to execute this lightbox divs according to the times written above. Or how to "kill" the lightbox with a push of a button.

Thanks for helping a noob [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img])

Share this post


Link to post
Share on other sites
Advertisement
I think you should call you script in body onload event?
http://www.w3schools.com/jsref/event_body_onload.asp

Then in your script, you check the local time, then display different DIVs according to the time range.

Share this post


Link to post
Share on other sites
Except if the page is running and then moves into those times it won't activate. You'll need to detect current time on document ready and then do some datetime trickery to set the box via setTimeout (with an action to change lightbox state and set another timeout for the next state change)

kinda dodgey though.

Share this post


Link to post
Share on other sites
Thanks for the answer! Yes, I called the script in the body onload, but my problem is that I don't know how to "connect" the script for lightbox and the time of day part. My idea to determine the time of day is following:

[CODE]
<SCRIPT type="text/javascript">


day = new Date()
hour = day.getHours()

if ((hour == 8) || (hour == 9) || (hour == 10) || (hour == 11) || (hour == 12) || (hour == 13) || (hour == 14) || (hour == 15) || (hour == 16))
{ // Show the red <div>
};
if ((hour == 17) || (hour == 18))
{// show the green <div> and "else - show no div
};
</SCRIPT>
[/CODE]

How can I incorporate the time determination in the light box script which I published in my first post?

@Telastyn: I doubt the situation will come so that I would need this - onload is good enough.

thanks!

Share this post


Link to post
Share on other sites
I've found another way to create a simple lightbox/colored area. But still can't combine all together.

So...

For Lightbox I have this:

[CODE]

<style>
.black_overlay{
display: none;
position: absolute;
top: 0%;
left: 0%;
width: 100%;
height: 100%;
background-color: black;
z-index:1001;
-moz-opacity: 0.8;
opacity:.80;
filter: alpha(opacity=80);
}

</style>


<body onload="document.getElementById('fade').style.display='block'">
<div id="fade" class="black_overlay"></div>
</body>
[/CODE]

And for time determination I found this (example time inputed):
[CODE]
<script type="text/javascript">
onload=function(){
var rightNow = new Date();
var hour = rightNow.getHours();
var newDisplay = 'none'; // unless we see otherwise
if((hour>= 1) && (hour<= 5)) {
newDisplay = 'block';
}
}

document.getElementById('fade').style.display=newDisplay"</script>
[/CODE]

I can't seem to connect those two to work like I want :/
Help is greatly appreciated!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement