Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-17-2013, 05:17 PM   PM User | #1
alex90
New to the CF scene

 
Join Date: Mar 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
alex90 is an unknown quantity at this point
javascript slideshow

i created a php code that saves in an array to names on the photos from a directory,next i would like to create a javascript slideshow that uses the array,not to load photos manually.i have and upload function on other page so it would be perfect to slideshow dynamically.any ideas?p.s i'm new to html,php,javascript
found this: where "altele/" is directory name and result is the array,but it doesn`t work
var curimg=0
function rotateimages(){
document.getElementById("slideshow").setAttribute("src", "altele/"+result[curimg])
curimg=(curimg<result.length-1)? curimg+1 : 0
}

window.onload=function(){
setInterval(rotateimages(), 2500)
}
alex90 is offline   Reply With Quote
Old 03-17-2013, 07:14 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
setInterval(rotateimages, 2500)

otherwise the function runs straight away and the setInterval tries to run what the function returns at the specified interval.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 03-17-2013, 08:20 PM   PM User | #3
alex90
New to the CF scene

 
Join Date: Mar 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
alex90 is an unknown quantity at this point
still no slideshow,it just shows the source image that i set
alex90 is offline   Reply With Quote
Old 04-13-2013, 05:45 PM   PM User | #4
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
Lightbulb

Quote:
Originally Posted by alex90 View Post
still no slideshow,it just shows the source image that i set
Works OK for me. Check your attempt against this.
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> Untitled </title>

<style type="text/css">
 #slideshow { margin: 50px 200px; }
</style>

</head>
<body>
<img id="slideshow">

<script type="text/javascript">
var baseURL = 'http://www.nova.edu/hpd/otm/pics/4fun/';
var result = ['11.jpg','12.jpg','13.jpg','14.jpg','15.jpg'];

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

window.onload=function(){
  document.getElementById('slideshow').src = baseURL+result[curimg];
  setInterval(rotateimages, 2500)
} 
</script>

</body>
</html>
Note: I did not have access to your image directory, so I used mine.
Change the 'baseURL' and result array filenames for your version.
jmrker is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, slideshow

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:51 AM.


Advertisement
Log in to turn off these ads.