묻고답하기
자바스크립트 변수가 잘 안 먹히네요
2008.01.10 04:24
<script>
function runSlideShow(object_01, a){
var slideShowSpeed = 3000
var crossFadeDuration = 3
var Pic = new Array()
name_object=object_01
Pic[0] = 'img/index_text_over_'+a+'.png'
Pic[1] = 'img/index_text_'+a+'.png'
var t
var j = 0
var p = Pic.length
var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}
if (document.all){
document.images.name_object.style.filter="blendTrans(duration=2)"
document.images.name_object.style.filter="blendTrans(duration=crossFadeDuration)"
document.images.name_object.filters.blendTrans.Apply()
}
document.images.name_object.src = preLoad[j].src
if (document.all){
document.images.name_object.filters.blendTrans.Play()
}
j = j + 1
if (j > (p-1)) j=0
//t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>
<img src=img/index_text_11.png border=0 onMouseover="runSlideShow(this.name,11)" name='over_01'>
<img src=img/index_text_12.png border=0 onMouseover="runSlideShow(this.name,12)" name='over_02'>
이상하게도 에러가 뜹니다. 중간에 document.images.name_object.style.filter 이 부분에서 함수 호출할때 name_object값이 안먹히네요
도저히 모르겠네요 좀 도와주세요 흑흑~
<script>
function runSlideShow(object_01, a){
var slideShowSpeed = 3000
var crossFadeDuration = 3
var Pic = new Array()
var name_object=object_01;
Pic[0] = 'img/index_text_over_'+a+'.png'
Pic[1] = 'img/index_text_'+a+'.png'
var t
var j = 0
var p = Pic.length
var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad[i] = new Image()
preLoad[i].src = Pic[i]
}
if (document.all){
document.getElementById(name_object).style.filter="blendTrans(duration=2)"
document.getElementById(name_object).style.filter="blendTrans(duration=crossFadeDuration)"
document.getElementById(name_object).filters.blendTrans.Apply()
}
document.getElementById(name_object).src = preLoad[j].src
if (document.all){
document.getElementById(name_object).filters.blendTrans.Play()
}
j = j + 1
if (j > (p-1)) j=0
//t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>
<img src=img/index_text_11.png border=0 onMouseover="runSlideShow('+ 'over_01',11)" id='over_01'>
<img src=img/index_text_12.png border=0 onMouseover="runSlideShow('over_02',12)" id='+ 'over_02'>
이렇게 수정해보세요.
document.images는 페이지내 이미지를 순차적으로 해서 document.images[0] ... 이런식으로 작성되야 합니다.
다른 방법도 있겠지만, 제가 아는 한도내에선 getElementById 를 쓰는데 가장 편하네요.