Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 5, 2008, 09:01 PM   #1
jdl8422
macrumors 6502
 
Join Date: Jul 2006
Location: Louisiana
Code for Randomly changing an image on a website

I am designing a website. There is a picture near the top header by the logo of the company. I want the picture to change out every so often automatically, not a rollover. It would be nice if it would fade in and out. Is this a flash thing? I am designing it using HTML/CSS. I would prefer to use that because I do not know flash. Thanks
__________________
jdl8422 is offline   0 Reply With Quote
Old Mar 5, 2008, 09:06 PM   #2
thejadedmonkey
macrumors 604
 
thejadedmonkey's Avatar
 
Join Date: May 2005
Location: Pa
Send a message via AIM to thejadedmonkey
It's pretty simple in flash... (haven't played around in flash in years though, don't recall how to)

you could use javascript.. for added fun, use AJAX!

or just make it an animated GIF.
__________________
MacBook Air • 17" MacBook Pro • iPod Nano • Apple TV
Custom Windows 7 Desktop • Surface RT • WP7
"Good judgment comes from experience,
experience comes from bad judgment."
- Mulla Nasrudin
thejadedmonkey is online now   0 Reply With Quote
Old Mar 5, 2008, 09:14 PM   #3
angelwatt
Demi-God (Moderator emeritus)
 
angelwatt's Avatar
 
Join Date: Aug 2005
Location: Ohio
It can be done with either JavaScript or Flash. Here's one way to do it with JavaScript, though no fade in/out.

Code:
<style type="text/javascript">
var images = new Array('image1.jpg', 'image2.jpg', 'etc');
function ChangeLogo()
{
  var i = document.getElementById('theImg');
  // randomly pick image from array
  i.src = images[Math.floor(Math.random()*i.length)];
  setTimeout("ChangeLogo()", 8000); // Change logo every 8 seconds
}
window.onload = ChangeLogo; // Start change once page loaded
</script>
Given this HTML exist
[HTML]<img id="theImg" src="image.jpg" alt="logo" />[/HTML]

See this site for some code for doing image transitions.

Last edited by angelwatt; Mar 5, 2008 at 09:34 PM. Reason: added link for image transitions
angelwatt is offline   0 Reply With Quote
Old Mar 5, 2008, 09:22 PM   #4
mason.kramer
macrumors 6502
 
Join Date: Apr 2007
Location: Watertown, MA
AFAIK, it can't be done in HTML/CSS. Your options are basically javascript or flash. The javascript way would be to install a javascript framework like jQuery or Scriptaculous or Mootools (and oy! don't ask which is best, what a can of worms that is! I use scriptaculous because that is integrated with my framework.)

The JS framework has functions which let you add "effects" to DOM elements (like a an IMG or a DIV containing an image). These effects are achieved by re-styling the CSS of the element many times very quickly, so it looks like a smooth transition, or fade, or color shift, or what have you.

For a picture switcher, you'll have to figure out a way to get all the pictures in the same spot as well. If you don't have a lot of pics, you could load them all into an array. If you do have a large pic library and don't want to the user to have to download them all, you're looking at AJAX requests.

Alternatively, you might be able to find a standalone javascript that does what you're looking for, probably as part of a larger javascript app that does what's lightbox effects, which is a fancy way of saying a js that displays pictures prettily.

What you're trying to do sounds simple, but it really isn't that simple. So if you're still learning html/css, you should probably put it aside for later.

Unless some clever chap around here knows a better way...

edit: Angelwatt beat me to it
mason.kramer is offline   0 Reply With Quote
Old Mar 5, 2008, 09:46 PM   #5
mason.kramer
macrumors 6502
 
Join Date: Apr 2007
Location: Watertown, MA
idea

Oo! Here's an idea. Try this lightbox program and make it a timed slideshow. Y

The docs are good and you can probably hack your way through it without knowing any javascript.

I've used this light box, I liked it.
mason.kramer is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

Similar Threads
thread Thread Starter Forum Replies Last Post
How long does it take for Apple to correct an error on their website? spinnerlys Apple, Industry and Internet Discussion 3 Jul 2, 2010 01:08 PM
Dragging an image on top of an image from the camera... pyroblue iPhone/iPad Programming 0 May 31, 2009 10:55 PM
How do I randomly rotate an image on a webpage after each page refresh? macaddict23 Web Design and Development 3 Jun 11, 2008 02:22 AM
Stitching Together images on a website Computer_Phreak Community 12 Apr 15, 2003 07:45 PM


All times are GMT -5. The time now is 08:30 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC