Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clock Widget

Status
Not open for further replies.

JoeLongstreet

Technical User
Jan 24, 2008
2
US
Hello, I am brand spanking new to JavaScript and I just wrote my first line of code. I have some experience with actionScript and from what I've looked at so far they seem fairly similar. Anyways, I am making a desktop widget and I need to place the time over an image and change the fonts. Here is the super simple code for the clock:

<script language = "JavaScript">
today = new Date();
document.write(today.getHours() + ":" + today.getMinutes());
</script>

I searched for some help around the internet but I wasn't really sure what this would be called. Any help would be much appreciated.

Thanks,

Joe Longstreet
 
What exactly are you asking for help with?

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Well I have an image and I want to place my javascript text on top of that image in a very specific place. Im just looking for a way to set the x position and y position of my javascript
 
You don't need to set the X and Y position of your javascript, just the text that it outputs.

Your best bet is to set up a DIV tag, using the image as the background, and the top and left padding values as the X and Y co-ordinates of your text

css:
Code:
#clockDiv {
 height: 100px;
 width: 200px;
 background-image: url(myimage.png);
 background-repeat: no-repeat;
 padding-top: 20px;
 padding-left: 50px;
}

HTML:
Code:
<div id="clockDiv"></div>

JS:
Code:
function clockTick(){
 var now = new Date();
 var hours = now.getHours();
 var minutes = "0" + now.getMinutes();
 minutes = minutes .slice(minutes.length - 2, minutes.length);
 vat strTime = hours + ":" + minutes;
 document.getElementById("clockDiv").innerHTML = strTime;
}


Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top