Javascript background clock Implementation Method

Source: Internet
Author: User

Javascript background clock Implementation Method

This article describes how to implement the javascript background clock. Share it with you for your reference. The details are as follows:

The following is all the code for this effect. [It is best to start with an empty page]

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

<Html>

<Head>

<TITLE> background clock </TITLE>

<Script language = javaScript>

<! --//

Function clockon (){

Thistime = new Date ()

Var hours = thistime. getHours ()

Var minutes = thistime. getMinutes ()

Var seconds = thistime. getSeconds ()

If (eval (hours) <10) {hours = "0" + hours}

If (eval (minutes) <10) {minutes = "0" + minutes}

If (seconds <10) {seconds = "0" + seconds}

Thistime = hours + ":" + minutes + ":" + seconds

If (document. all ){

Bgclocknoshade. innerHTML = thistime

Bgclockshade. innerHTML = thistime

}

If (document. layers ){

Document.bgclockshade.doc ument. write ('<div id = "bgclockshade" style = "position: absolute; visibility: visible; font-family: Verdana; color: FFAAAAA; font-size: 120px; top: 10px; left: 152px "> '+ thistime +' </div> ')

Document.bgclocknoshade.doc ument. write ('<div id = "bgclocknoshade" style = "position: absolute; visibility: visible; font-family: Verdana; color: dddddddd; font-size: 120px; top: 10px; left: 150px "> '+ thistime +' </div> ')

Document. close ()

}

Var timer = setTimeout ("clockon ()", 200)

}

// -->

</Script>

<Link rel = "stylesheet" href = "../style.css">

<Body onLoad = "clockon ()">

<Div id = "bgclockshade" style = "position: absolute; visibility: visible; font-family: Arial; color: FF8888; font-size: 120px; top: 102px; left: 152px "> </div>

<Div id = "bgclocknoshade" style = "position: absolute; visibility: visible; font-family: Arial; color: dddddddd; font-size: 120px; top: 100px; left: 150px "> </div>

<Div id = "mainbody" style = "position: absolute; visibility: visible">

</Div>

</Body>

</Html>

Note: You must correct the TOP and LEFT parameters to determine the position of the clock display. The TOP layer is the pixel value from the TOP of the display. LEFT indicates the pixel value from the LEFT.

I hope this article will help you design javascript programs.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.