473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

JavaScript vs. .gif

71
I'm looking to make a slideshow of sorts... essentially I have 4-5 images that I want to cycle through on about a 5secon per image loop.

I'm wondering if it would be more efficient, as far as page load & image load times, to just a javascript that cycles through .jpg images; or to make an animated .gif file that cycles through the images. Anyone have any thoughts on this?
Jun 7 '07 #1
1 1279
iam_clint
1,208 Expert 1GB
making a gif would probably be less efficient in the way that what if you want to change an image in the rotation, remove one, or add a new one


i would say use javascript.


all you need is an array of images. Example provided
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body onload="startSlides();">
  3. <script>
  4. //script provided by iam_clint -- tsdn -- www.thescripts.com
  5. var current = 0;
  6. var imgs = ['1.jpg', '2.jpg', '3.jpg'];
  7. var timer;
  8. var delay = 5000; //milliseconds 5000 = 5 seconds
  9.  
  10. function startSlides() {
  11.     swapImage();
  12.     timer = window.setInterval("swapImage()", delay);
  13. }
  14.  
  15. function swapImage() {
  16.     var img_holder = document.getElementById("imgholder");
  17.     imgholder.src = imgs[current];
  18.     if (current == imgs.length-1) { current = 0; } else { current += 1; }
  19. }
  20. </script>
  21. <img src="" id="imgholder">
  22. </body>
  23. </html>
  24.  
Jun 7 '07 #2

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

Similar topics

0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.