2010-12-05 22 views
1

I developed a html page with a bit of javascript. I have several tags and after clicking a link one of them is dynamically assigned a background image. This url is stored in a global variable. So far so good.html/javascript : <a href>

var picture,thumb 

function changeDivs(p) 
{ 
    if (p!='') { 
     picture = './images/p'+p+'.jpg'; // global url variable 
     thumb = './thumbs/p'+p+'.jpg'; // global url variable 
     var pic = "url("+thumb+")"; 
     document.getElementById("poster").style.backgroundImage = pic; 
     } 
} 

I call the function like this:

<a href="javascript:changeDivs('2')">Link</a> 

Now I want to make use of a thumbnailviewer script which needs to be accessed like this:

<a href="javascript: global variable" rel="thumbnail"> <!-- Of course this "javascript: global variable" should be a valid url: the stored 'picture' variable --> 
     <div id="poster"> 
     </div> 
    </a> 

So I have stored the url in variable: picture

How can I access the thumbnailviewer script through <a href> AND use the variable. I don't know if the thumbnail script can be called through a function or how.

Thanks a lot!

+0

다른 사람이 나를 도울 수 있기를 바라고 인트로를 삭제했습니다. 그것이 우리가 여기있는 모든 것입니다. 그래서 우리는 당신의 질문을보고 있습니다, 그래서 당신은 좋은 손에 있습니다. stackoverflow에 오신 것을 환영합니다! : D –

+1

changeDivs (p)에서 p는 어디에서 얼마나 정확하게 얻고 있습니까? – kjy112

+0

이것은 changeDivs 함수를 호출하는 방법입니다.

답변

1

I think this is what you are attempting to achieve. Here is the jsfiddle에 대한 URL을 변수로 사용합니다. '<a href>' 이미지를 클릭
는 나는 기존의 미리보기 이미지 URL로 그림의 URL을 대체 "<div id='poster'>"

의 배경이된다. 사진 및 썸 변수의 URL이 있는지 확인하십시오. 또한, 너의 포스터의 div의 너비와 높이를 설정합니다.

썸네일 뷰어로 작업하려면 새로운 jsfiddle 링크를 사용해주세요. 참고로, dynamicdrive는 jsfiddle이 js 파일에 액세스하는 것을 차단했습니다. 자신의 프로젝트에있는 코드를 사용해보십시오.

+0

작동하지 않는다. 축소 이미지 뷰어가 열리지 만 그림은 표시되지 않습니다. (그것은 href url이 필요합니다 - 내 변수입니다). 그러나 지금 당신은 문제를 안다. :) 고마워. 지금까지 –

+0

이것은 플러그인의 문제일지도 모른다. DOM이 jQuery의 NivoSlider를 사용하여 VIA javascript를 준비한 후 동적 로딩과 비슷한 문제가 발생했습니다. 나는 이것이 사실인지 알기 위해 thumbnailviewer와 친숙하지 않다. – kjy112

+0

시도해 주셔서 감사합니다. 이후 오전 5시 여기에 ... 나는 자루를 칠거야 :) 다시 한번 감사드립니다. –

관련 문제