English 中文(简体)
从幻灯片的图像中获取图像
原标题:Get image src from a image in a slideshow

我今天一直在研究,花几个小时试图做些事情。 对于一名客户,我用一个灯塔在点击图像时,正在制造滑坡。 幻灯和灯塔都是工作,但我并没有在光箱中看到正确的形象。

This is the code that loads the slideshow and when clicked on an image opens the lightbox. (The images for the slideshow get loaded by a php script and turned into a Javascript array)

<script type="text/javascript">

var curimg=0;
function rotateimages(){
document.getElementById("slideshow").setAttribute("src", "images/"+galleryarray[curimg]);
curimg=(curimg<galleryarray.length-1)? curimg+1 : 0;
}

window.onload = function(){
setInterval("rotateimages()", 1000);
}
</script>
<div style="width: 170px; height: 160px">
<a href = "javascript:void(0)" onclick =          "document.getElementById( light ).style.display= block ;document.getElementById( fade ).style.    display= block ">
<img id="slideshow" src="" />
</a>
<div id="light" class="white_content">
<img id="lightImg" src="" />
<script>
var image = document.getElementById("slideshow").src;
document.getElementById("lightImg").setAttribute("src", image);
</script>

我现在试图制造一个称为“im”的变量,让它包含目前幻灯中的形象。 因此,我可以把这个问题带上光箱中的形象。

希望有些人能给我一些有益的建议。 在 Java文中,我很新。

幻灯的文字来自:

关于Koen。

最佳回答

这些日子实际上没有使用侵扰式 Java字的借口(在你的超文本属性范围内,最好放在外部档案中。”

I have done you the favour of cleaning up your code a bit, and changed it where you seemed to be going wrong. As DotNetter has already pointed out it would be sensible to use jQuery in this instance, as it really does simplify things. However, I m going to assume that for some reason you want it in plain js. Below is a simplification of the code that you posted with the correct change.

<style type="text/css">
    .wrapper {
        width: 170px;
        height: 160px;
    }
</style>

<script type="text/javascript">
    var curimg=0;
    function rotateimages(){
        document.getElementById("slideshow").setAttribute("src", "images/" + galleryarray[curimg]);
        curimg=(curimg<galleryarray.length-1)? curimg+1 : 0;
    }

    window.onload = function(){
        setInterval("rotateimages()", 1000);

        document.getElementById("slideshow").onclick = function () {
            var imageSrc = document.getElementById("slideshow").src;
            document.getElementById("lightImg").setAttribute("src", imageSrc);
            document.getElementById( light ).style.display =  block ;
            document.getElementById( fade ).style.display =  block ;
        }
    }
</script>

<div class= wrapper >
    <img id="slideshow" src="" />
    <div id="light" class="white_content">
        <img id="lightImg" src="" />
    </div>
</div>

此前,当网页上装时,你正在接上目前图像的弧线,当用户点击时,你需要接上图像的弧线。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签