-1

I have the following code, i use the php file to read contents of a folder put it into an array and then have a slideshow using Jquery Cycle plugin.

<html>
<meta http-equiv="refresh" content="1000"/> 
head>
<title>Media Signage Slideshow</title>
<style type="text/css">
    #myslides {
    width: 370px;
    height: 220px;
    padding: 0;  
    margin:  0 auto;  
} 
     </style>
</head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

<script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$('#myslides').cycle({
               fx: 'fade',
                speed: 5000,
                timeout: 2000
        });
});
</script>

<script type="text/javascript">

var curimg=0;
function rotateimages(){
galleryarray.sort();
document.getElementById("myslides").setAttribute("src", "images/"+galleryarray[curimg]);
curimg = (curimg+1) % galleryarray.length;
}

window.onload = function(){
setInterval("rotateimages()", 5000);
}
/script>

<script type="text/javascript" language="JavaScript" src="./code.php"></script>
<body>
<div id="myslides">
  <!--<img src="100.jpg" />
  <img src="101.jpg" /> -->
</div>
</body>
</html>

when i change:

<div id="myslides">

to

<img id="myslides">

my slide show works fine but with div id i dont see anything. How to fix this?

4

4 に答える 4

2

Images have the source attribute, which your jquery is using, while divs don't. That's why :)

于 2012-04-11T20:29:02.393 に答える
0

Changing #myslides to a div would mean you're trying to set the src of a div element which makes no practical sense at all (and doesn't validate). What are you trying to achieve?

于 2012-04-11T20:28:12.440 に答える
0

Take a look to this part of your code:

document.getElementById("myslides").setAttribute("src", "images/"+galleryarray[curimg]);

You can't access it cuz the DIV element doesn't had the "src" attribute. So u can't set an image for it with your plugin.

于 2012-04-11T20:31:51.970 に答える
0

If you need a div for any reason, why not just wrap the img in it?

<div><img id="myslides" /><div>
于 2012-04-11T20:34:35.793 に答える