Online Documentation Server
 ПОИСК
ods.com.ua Web
 КАТЕГОРИИ
Home
Programming
Net technology
Unixes
Security
RFC, HOWTO
Web technology
Data bases
Other docs

 


 ПОДПИСКА

 О КОПИРАЙТАХ
Вся предоставленная на этом сервере информация собрана нами из разных источников. Если Вам кажется, что публикация каких-то документов нарушает чьи-либо авторские права, сообщите нам об этом.




Графические часы

Домашняя страница Алексея Александрова

Первый пример - это часы, отображающие время загрузки страницы (т.е. момент вызова скрипта). Используются методы объекта Date (getHours, getMinutes) и графические файлы, отображающие полученное время (имена этих файлов соответствуют цифрам - 0-9).

Во втором примере, отображающем текущую дату, также используются методы объекта Date (getDate, getMnth, getYear) и графические файлы, отображающие полученную дату (имена этих файлов соответствуют цифрам - 0-9).

1.
<SCRIPT LANGUAGE="JavaScript">
<!--
// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that this
// notice remains as is.
// Additional scripts can be found at http:
//www.geocities.com/~yehuda
/// image files needed:
// dg0.gif
// dg1.gif 
// dg2.gif
// dg3.gif
// dg4.gif
// dg5.gif
// dg6.gif
// dg7.gif
// dg8.gif
// dg9.gif
// dgam.gif
// dgpm.gif
// dgc.gif
// Any set of digit images (0-9), an "am" image,
// a "pm" image, and a colon image respectively
// will work with this script.  
// instructions:
// Place all image files in a folder / directory. 
// Add this script, including all comments, to 
// the desired HTML document. The HTML file must
// be located in the same directory as the image
// files.
document.write(setClock())
function setClock() {
// initialize accumulative HTML variable to empty string
var text = "" 

// set standard convention for digit and punctuation images 
var openImage = "<IMG SRC=\"" + getPath(location.href) + "dg"
var closeImage = ".gif\"HEIGHT=21 WIDTH=16>"
//  initialize time-relatedvariables with current time settings
var now =  newDate() varhour=now.getHours()
var minute = now.getMinutes() now = null
var ampm = ""
// validate hour values and
//set value of ampm
if (hour > = 12) {
hour -= 12
ampm = "pm"
} else
ampm = "am"
hour = (hour == 0) ? 12 : hour
// add zero digit to a one digit minute as spaceholder
if (minute < 10)
minute = "0" + minute 
// do not parse this number!
// convert minute and hour values to strings
minute += ""
hour += ""
// assign image tags according to the value of hour
for (var i = 0; i < hour.length; ++i) {
text += openImage + hour.charAt(i) + closeImage
}
// assign image tag of colon separator to text variable
text += openImage + "c.gif\" HEIGHT= 21WIDTH=9>"
// assign image tags according to the value of minute
for (var i = 0; i < minute.length; ++i) {
text += openImage + minute.charAt(i) + closeImage
}
// assign am / pm image tag to text variable
text += openImage + ampm + closeImage
// return accumulative HTML string
return text}function getPath(url) {
lastSlash = url.lastIndexOf("/")
return url.substring(0, lastSlash + 1)}
// -->
</SCRIPT>
2.
<SCRIPT LANGUAGE="JavaScript">
<!--
// Copyright (c) 1996-1997 Tomer Shiran. All rights reserved.
// Permission given to use the script provided that
// this notice remains as is.
// Additional scripts can be found at http:
//www.geocities.com/~yehuda
/// image files needed:
// *******************
// dg0.gif
// dg1.gif 
// dg2.gif
// dg3.gif
// dg4.gif
// dg5.gif
// dg6.gif
// dg7.gif
// dg8.gif
// dg9.gif
// dgp.gif
// Any set of digit images (0-9), and a period
// image (.) will work with this script.  
// instructions:
// *************
// Place all image files in a folder / directory. 
// Add this script, including all comments, to 
// the desired HTML document. The HTML file must
// be located in the same directory as the image
// files.
document.write(setDate())
function setDate() {
// initialize accumulative HTML variable to empty string
var text = "" 
// set standard convention for digit and punctuation images 
var openImage = "<IMG
 SRC=\""+getPath(location.href)+"dg"
var closeImage = ".gif\" HEIGHT=21 WIDTH=16>"
// initialize time-related variables with current date settings
var now=new Date()
var month = now.getMonth()
var date= now.getDate()
var year= now.getYear()now=null
// convert  integer value
//of month  to
//standard range  month++
// 0  -
11 = 
        
    >  1 - 12
// convert minute and hour values to strings
month += ""
date += ""
year += ""
// assign image tags associated with month to text variable 
for (var i = 0; i < month.length; ++i) {
text += openImage + month.charAt(i) + closeImage
}
// assign image tag of period separator to text variable
text += openImage + "p.gif\"
HEIGHT= 21WIDTH=9>" 
// assign image tags associated with date to text variable 
for (var i = 0; i < date.length; ++i) {
text += openImage + date.charAt(i) + closeImage
}
// assign image tag of period separator to text variable
text += openImage + "p.gif\" HEIGHT= 21WIDTH=9>" 
// assign image tags associated with year to text variable 
for (var i = 0; i < year.length; ++i) {
text += openImage + year.charAt(i) + closeImage
}
// return accumulative HTML string
return text}function getPath(url) {
lastSlash = url.lastIndexOf("/")
return url.substring(0, lastSlash + 1)}
// -->
</SCRIPT>


Comments: info@citmgu.ru
Copyright © CIT


With any suggestions or questions please feel free to contact us