첫 번째 자바 스크립트 클래스 (총 멍청한 놈)를 가져 가고 있으며 할당 중 하나는 빨간색에서시, 초록색, 초에서 파란색으로 변경 한 다음 변경되면 각 색상 구성 요소가 증가합니다. 나는 십진수 값 (예 : "# 850000")을 각 요소 (시, 분, 초)에 성공적으로 할당했지만, 뇌가 튀어서 시간, 분, 초가 바뀔 때 밝기를 증가시키는 방법을 알아 내려고 시도합니다 "# 870000"이 오후 1:00:00에서 2:00:00로 바뀝니다. 나는 이것을 성공적으로 수행하는 방법에 대한 도움없이 어디에서나 검색했습니다. 크게 감상 할 수디지털 시계의 시간 (r), 분 (g), 초 (b)마다 RGB 구성 요소를 늘립니다.
이TJ
<script type="text/javascript">
<!--
function updateClock()
{
var currentTime = new Date();
var currentHours = currentTime.getHours();
var currentMinutes = currentTime.getMinutes();
var currentSeconds = currentTime.getSeconds();
// Pad the minutes with leading zeros, if required
currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
// Pad the seconds with leading zeros, if required
currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;
// Choose either "AM" or "PM" as appropriate
var timeOfDay = (currentHours < 12) ? "AM" : "PM";
// Convert the hours component to 12-hour format
currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
// Convert an hours component if "0" to "12"
currentHours = (currentHours == 0) ? 12 : currentHours;
// Get hold of the html elements by their ids
var hoursElement = document.getElementById("hours");
document.getElementById("hours").style.color = "#850000";
var minutesElement = document.getElementById("minutes");
document.getElementById("minutes").style.color = "#008500";
var secondsElement = document.getElementById("seconds");
document.getElementById("seconds").style.color = "#000085";
var am_pmElement = document.getElementById("am_pm");
// Put the clock sections text into the elements' innerHTML
hoursElement.innerHTML = currentHours;
minutesElement.innerHTML = currentMinutes;
secondsElement.innerHTML = currentSeconds;
am_pmElement.innerHTML = timeOfDay;
}
// -->
</script>
</head>
<body onload="updateClock(); setInterval('updateClock()', 1000)">
<h1 align="center">The JavaScript digital clock</h1>
<h2 align="center">Thomas Fertterer - Lab 2</h2>
<div id='clock' style="text-align: center">
<span id="hours"></span>:
<span id='minutes'></span>:
<span id='seconds'></span>
<span id='am_pm'></span>
</div>
</body>
</html>
관련의 일부 : http://collegesnippets.blogspot.com/2011/09/time-color.html – Ivan