Jump to content

  • Log In with Google      Sign In   
  • Create Account

Different div/lightbox for different time of day


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 sebr1ng   Members   -  Reputation: 100

Like
0Likes
Like

Posted 27 March 2012 - 07:18 AM

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:
<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>

and Div's

<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>


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 Posted Image)

Sponsor:

#2 wqking   Members   -  Reputation: 756

Like
0Likes
Like

Posted 27 March 2012 - 07:44 AM

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.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#3 Telastyn   Crossbones+   -  Reputation: 3726

Like
0Likes
Like

Posted 27 March 2012 - 07:58 AM

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.

#4 sebr1ng   Members   -  Reputation: 100

Like
0Likes
Like

Posted 28 March 2012 - 07:01 AM

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:

<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>

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!

#5 sebr1ng   Members   -  Reputation: 100

Like
0Likes
Like

Posted 31 March 2012 - 06:00 PM

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:

 
<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>

And for time determination I found this (example time inputed):
<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>

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS