• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Kristian Gorenc

Different div/lightbox for different time of day

4 posts in this topic

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])
0

Share this post


Link to post
Share on other sites
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.
0

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

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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0