시간별로 이미지 다르게?
본문
시간별로 이미지가 다르게 보여지는 소스를 사용중입니다.
이 소스에서 평일과 주말은 이미지가 다르게 보여지는데 평일에는 시간별로 이미지 지정이 가능한데 주말은 1개의 이미지를 사용하거든요.
주말(토요일,일요일)에도 시간별로 이미지를 적용하려면 어찌해야할까요? (평일 이미지와 다른이미지를 사용해야함..)
소스 원문입니다.
<script language="Javascript">
<!--
day=new Date() ;
var d = '<?=date('w')?>';
var x = '<?=date('H')?>';
if ((d == 6 && x >= 1) || d == 0) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_01.png">');
} else {
x=day.getHours() ;
if(x>=0 && x<11) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_02.png">');
} else
if(x>=11 && x<12) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_04.png">');
} else
if(x>=12 && x<13) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_03.png">');
} else
if(x>=13 && x<18) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_04.png">');
} else
if(x>=18 && x<20) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_02.png">');
} else
if (x>=20 && x<24) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_02.png">');
}
}
//-->
</script>
빨간부분이 주말 이미지인듯한데 이부분을 시간별로 적용가능할지.. 고수님들 도와주세요..ㅠㅠ
답변 1
var d = '<?=date('w')?>';
var x = '<?=date('H')?>';
x=day.getHours() ; << 이 줄은 위로 빼놓고..
평일꺼 그대로 갖다 넣으면 안되려나요. 이렇게..
if ((d == 6 && x >= 1) || d == 0) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_01.png">');} else {
여기를 아래처럼.. 이미지는 교체하시면 되고요.
if ((d == 6 && x >= 1) || d == 0) {
if(x>=0 && x<11) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_02.png">');
} else
if(x>=11 && x<12) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_04.png">');
} else
if(x>=12 && x<13) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_03.png">');
} else
if(x>=13 && x<18) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_04.png">');
} else
if(x>=18 && x<20) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_02.png">');
} else
if (x>=20 && x<24) {
document.write('<img src="<?=$g4['path']?>/img/qna_notice_02.png">');
}
} else {