473,624 Members | 2,575 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript slideshow issues with getElementById.

helimeef
77 New Member
Hiya, I'm upgrading a this slideshow to Object Oriented code (so I can reuse it for other clients), and I'm having some problems getting the library to work. Here is what it's like so far:
Expand|Select|Wrap|Line Numbers
  1. (function(){
  2.     var img;
  3.     var imgArr;
  4.     var currSlide = 0;
  5.     function Slideshow(image,slides) {
  6.         img = document.getElementById(image);
  7.         imgArr = slides;
  8.         this.Next=function(amount) {
  9.             if(!amount) var amount=1;
  10.             if(currSlide+1<imgArr.length) {
  11.                 currSlide+=amount;
  12.             }
  13.             else {
  14.                 currSlide = 0;
  15.             }
  16.             img.src = imgArr[currSlide];
  17.             return this;
  18.         }
  19.         this.Prev = function(amount) {
  20.             if(!amount) var amount=1;
  21.             if(currSlide>0) {
  22.                 currSlide-=amount;
  23.             }
  24.             else {
  25.                 currSlide = imgArr.length-1;
  26.             }
  27.             img.src = imgArr[currSlide];
  28.             return this;
  29.         }
  30.     }
  31. })();
To create a slideshow and go to the next image (if it worked) you would do this:
Expand|Select|Wrap|Line Numbers
  1. var Show = new Slideshow('id_of_image_to_rotate',['img1.png','img2.jpg','img3.gif']);
  2. Show.Next();
However when I do this, HomeSite and FF Error Console tell me "document.getEl emenyById(...) is null or not an object". I have fixed it by wrapping all of the code in window.onload, but what kind of library would require that? I figured that (function() {}); was used to remove that error, but I guess not.
Any ways I can fix this?
Oct 11 '07 #1
2 1351
acoder
16,027 Recognized Expert Moderator MVP
Functions are objects, see An Introduction to Function Objects.
Oct 15 '07 #2
helimeef
77 New Member
Functions are objects, see An Introduction to Function Objects.
Well, that really wasn't my problem (I think), but I got it to work anyway. I ended up doing this:
Expand|Select|Wrap|Line Numbers
  1. var Slideshow;
  2. Slideshow = (function(image_id,slides){
  3.   //the rest...
  4. });
  5. // The code that activates the slideshow
  6. window.onload = function() {
  7.   var show = new Slideshow('image_id',{'1.jpg','2.jpg'});
  8.   show.Next().Previous().Whatever();
  9. }
So I needed to put the code in window.onload. There ya go.
Oct 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2094
by: Jeannie | last post by:
I have a popup window which is a slideshow of about 7 images. When the popup window loads, the first image is present and then the viewer can select next or previous to scroll through the rest of the images. I'd like to use the same popup window at different points throughout the website and have the Virtual Tour (slideshow) open up at the appropriate photos. Meaning I'd like to control which picture the popup window opens up to,...
4
2726
by: CB US 77 | last post by:
I use a piece of javascript to create a photo gallery slideshow. The slideshow part works great, but I would like to add captions to each picture. If you want to see the html, send me an email to usb15@cox.net. Any help would be great.
5
4131
by: Brian.Steele | last post by:
Greetings everyone. See http://www.spiceisle.com/cgi-bin/slideshow/slideshow.cgi?dir=brian/personal/2005/uk_trip/images&type=jpg The "Pause" button works in IE, but not in Firefox. Any ideas why? If you have any other ideas on how the javascript can be improved, please let me know.
15
4210
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is avaliable at... http://www.geocities.com/binnyva/code/javascript/advanced_tutorial/ If any of you could spare the time, please have a look at my tutorial
1
1270
by: titch350 | last post by:
Does anyone know how to do a Javascript Slideshow with a loop i have a code but i cant get it to work: this is the code: picno = 0 function showpic(item) { document.getElementById("pic0").src = item.href document.getElementById("subtitle").firstChild.nodeValue = item.title
6
2150
by: webmaster1 | last post by:
Hi, Im not a Java programmer, I do a PHP programs, but now I must implement a Java script for a poicture slideshow. With this script I can change pictures from examlpe 1 to 10. But I must to do that i have a 4 pictures in a row and each picture will change 3 pictures => 4 x 3 picture for change. this code swap the pictures: <script language="JavaScript">
3
3850
by: krzysztof.murkowski | last post by:
Hi, I have problem with JavaScript for gallery of images. From the overview page with thumbnails, after a click on the small picture, the subpage 'slide_show.html' is called, with a number of picture as parameter for example: <a href=slide_show.html?nb=2> (The code is at the end of this post)
0
8249
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8179
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8348
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4187
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1797
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1493
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.