CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Post a JavaScript (http://www.codingforums.com/forumdisplay.php?f=19)
-   -   Carousel Slideshow (http://www.codingforums.com/showthread.php?t=58814)

Harry Armadillo 05-10-2005 06:14 PM

Carousel Slideshow
 
A question was posted in the Dynamic Drive forum about this slideshow script. I liked the effect, but hated the scripting...so I reverse engineered it.
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>Carousel Slideshow</title>
<script type='text/javascript'>
function carousel(params){
  if(!(params.width>0&&isFinite(params.width)))params.width=100;
  if(!(params.height>0&&isFinite(params.height)))params.height=100;
  if(!(params.sides>2&&isFinite(params.sides)))params.sides=4;
  if(!(params.steps>0&&params.steps<100&&isFinite(params.steps)))params.steps=20;
  if(!(params.speed>0&&isFinite(params.speed)))params.speed=8;
  if(!(params.image_border_width>=0&&isFinite(params.image_border_width)))params.image_border_width=0;
  if(isFinite(params.id)||!params.id)params.id='bad_id_given_'+Math.random();
 
  document.write("<div style='position:relative;overflow:hidden;' id='"+params.id.replace(/[\r\n\t ]+/g,'_')+"'></div>");
  var cdiv=document.getElementById(params.id.replace(/[\r\n\t ]+/g,'_'))
  cdiv.style.width=params.width+'px';
  cdiv.style.height=params.height+'px';
  cdiv.style.border=params.border;
  cdiv.style.position='relative';
  cdiv.style.overflow='hidden';
  cdiv.title=params.id;
   
  var counter=0,spinning=true,interval=Math.floor(60000/params.sides/params.steps/params.speed)-5;
  interval=isNaN(interval)?200:interval;
  var img_position=[],images=[],img_dimension=[];
  var img_index=params.images.length+1,img_index_cap=2*params.images.length;
  var faces=Math.ceil(params.sides/2), dimension, direction;

  function init(){
    if(params.direction=="left" || params.direction=="right"){
      direction=params.direction;
      dimension="width";
      }
    else if(params.direction=="top" || params.direction=="bottom"){
      direction=params.direction;
      dimension="height";
      }
    else {
      direction="left";
      dimension="width";
      }     
    cdiv.style[dimension]=params[dimension]/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)+'px';
    var img=new Image();
    img.style.position='absolute';
    img.style[direction]='10000px';
    img.style.width=params.width-2*params.image_border_width+'px';
    img.style.height=params.height-2*params.image_border_width+'px';
    img.style.border=(params.image_border_width||0)+'px solid '+params.image_border_color;
 
    for(var i=0;i<params.images.length;i++){
      images[i]=img.cloneNode(true);
      images[i].src=params.images[i];
      if(params.links&&params.links[i]&&params.links[i]!=''){
        images[i].onclick=new Function("window.location='"+params.links[i]+"'");
        images[i].style.cursor=document.all?'hand':'pointer';
        }
      if(params.titles&&params.titles[i]&&params.titles[i]!='')
        images[i].title=params.titles[i];
      images[i+params.images.length]=images[i];
      if(params.images.length==faces)
        images[i+2*params.images.length]=images[i];
      cdiv.appendChild(images[i]);
      }
 
    var face_size=params.size_mode=='image'?params[dimension]:params[dimension]*Math.sin(Math.PI/params.sides);
    var face_offset=params[dimension]*Math.cos(Math.PI/params.sides)/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)/2-.5;
    var pi_piece=2*Math.PI/params.steps/params.sides;
    for(i=0;i<=params.steps*faces;i++){
      img_dimension[i]=face_size*Math.sin(pi_piece*i);
      img_position[i]=(i<params.steps*params.sides/2)?Math.floor(params[dimension]/2/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)-face_offset*Math.cos(pi_piece*i)-img_dimension[i]/2)+'px':'10000px';
      img_dimension[i]=img_dimension[i]-2*params.image_border_width>1?Math.ceil(img_dimension[i])-2*params.image_border_width+'px':'1px';
      }
    }
  init();

  cdiv.rotate = function(){
    setTimeout('document.getElementById("'+cdiv.id+'").rotate()',interval);
    if(!spinning) return;
    if(++counter>=params.steps){
      counter=0;
      if(++img_index>=img_index_cap)
        img_index=params.images.length;
      }
    images[img_index-faces].style[direction]='20000px';
    for(var i=faces-1;i>=0;i--){
      images[img_index-i].style[direction]=img_position[counter+i*params.steps];
      images[img_index-i].style[dimension]=img_dimension[counter+i*params.steps];
      }
    }
  cdiv.onmouseover=function(){
    spinning=false;
    }
  cdiv.onmouseout=function(){
    spinning=true;
    }
  setTimeout('document.getElementById("'+cdiv.id+'").rotate()',200);
  }
</script>
</head><body>
<div id=right_bar style='width:90px;float:right;'>
<h4>Vertical!</h4>More steps (affects speed slightly)
<script type='text/javascript'>
carousel({id:'carousel_0',
          border:'',
          size_mode:'image',
          width:75,
          height:75,
          sides:18,
          steps:8,
          speed:7,
          direction:'top',
          images:['http://www.codingforums.com/images/icons/icon7.gif',
                  'http://www.codingforums.com/images/icons/icon8.gif',
                  'http://www.codingforums.com/images/icons/icon3.gif',
                  'http://www.codingforums.com/images/icons/icon4.gif',
                  'http://www.codingforums.com/images/icons/icon5.gif',
                  'http://www.codingforums.com/images/icons/icon9.gif',
                  'http://www.codingforums.com/images/icons/icon10.gif',
                  'http://www.codingforums.com/images/icons/icon13.gif',
                  'http://www.codingforums.com/images/icons/icon12.gif',
                  'http://www.codingforums.com/images/icons/icon11.gif',
                  'http://www.codingforums.com/images/icons/icon2.gif',
                  'http://www.codingforums.com/images/icons/icon6.gif'],
          links: [],
          titles:[],
          image_border_width:2,
          image_border_color:'black'
          });
</script></div>
<div id=right_pub style='width:90px;float:right;'>
<h4>Vertical!</h4>Less steps (affects speed slightly)
<script type='text/javascript'>
carousel({id:'carousel_5',   
          border:'',
          size_mode:'carousel',
          width:75,
          height:430,
          sides:18,
          steps:4,
          speed:7,
          direction:'bottom',
          images:['http://www.codingforums.com/images/icons/icon7.gif',
                  'http://www.codingforums.com/images/icons/icon8.gif',
                  'http://www.codingforums.com/images/icons/icon3.gif',
                  'http://www.codingforums.com/images/icons/icon4.gif',
                  'http://www.codingforums.com/images/icons/icon5.gif',
                  'http://www.codingforums.com/images/icons/icon9.gif',
                  'http://www.codingforums.com/images/icons/icon10.gif',
                  'http://www.codingforums.com/images/icons/icon13.gif',
                  'http://www.codingforums.com/images/icons/icon12.gif',
                  'http://www.codingforums.com/images/icons/icon11.gif',
                  'http://www.codingforums.com/images/icons/icon2.gif',
                  'http://www.codingforums.com/images/icons/icon6.gif'],
          links: [],
          titles:[],
          image_border_width:2,
          image_border_color:'black'
          });
</script></div><div id='header' style='height:175;padding:10px;background-color:#eee;width:570px'><div style='float:left'>
<script type='text/javascript'>
carousel({id:null,
          border:'',
          size_mode:'image',
          width:{},
          height:'big',
          sides:'several',
          steps:8/0,
          speed:'really fast',
          direction:'whatever',
          images:['http://www.codingforums.com/images/icons/icon7.gif',
                  'http://www.codingforums.com/images/icons/icon8.gif',
                  'http://www.codingforums.com/images/icons/icon9.gif',
                  'http://www.codingforums.com/images/icons/icon10.gif',
                  'http://www.codingforums.com/images/icons/icon2.gif',
                  'http://www.codingforums.com/images/icons/icon3.gif',
                  'http://www.codingforums.com/images/icons/icon4.gif',
                  'http://www.codingforums.com/images/icons/icon5.gif',
                  'http://www.codingforums.com/images/icons/icon6.gif'],
          links: ['http://www.google.com/search?q=happy',
                  'http://www.google.com/search?q=angry',
                  'http://www.google.com/search?q=sad',
                  'http://www.google.com/search?q=big+grin',
                  'http://www.google.com/search?q=look+here',
                  'http://www.google.com/search?q=bright+idea',
                  'http://www.google.com/search?q=caution',
                  'http://www.google.com/search?q=question',
                  'http://www.google.com/search?q=cool'],
          titles:['Happy',
                  'Angry',
                  'Sad',
                  'Big Grin',
                  'Look Here',
                  'Bright Idea',
                  'Caution',
                  'Question',
                  'Cool!'],
          image_border_width:1,
          image_border_color:'red'
          });
</script></div><div style='float:left'>
<script type='text/javascript'>
carousel({id:'carousel_2',
          border:'',
          size_mode:'carousel',
          width:144,
          height:100,
          sides:4,
          steps:20,
          speed:8,
          direction:'right',
          images:['http://www.codingforums.com/images/icons/icon7.gif',
                  'http://www.codingforums.com/images/icons/icon8.gif',
                  'http://www.codingforums.com/images/icons/icon9.gif',
                  'http://www.codingforums.com/images/icons/icon10.gif',
                  'http://www.codingforums.com/images/icons/icon2.gif',
                  'http://www.codingforums.com/images/icons/icon3.gif',
                  'http://www.codingforums.com/images/icons/icon4.gif',
                  'http://www.codingforums.com/images/icons/icon5.gif',
                  'http://www.codingforums.com/images/icons/icon6.gif'],
          links: ['http://www.google.com/search?q=happy',
                  'http://www.google.com/search?q=angry',
                  'http://www.google.com/search?q=sad',
                  'http://www.google.com/search?q=big+grin',
                  'http://www.google.com/search?q=look+here',
                  'http://www.google.com/search?q=bright+idea',
                  'http://www.google.com/search?q=caution',
                  'http://www.google.com/search?q=question',
                  'http://www.google.com/search?q=cool'],
          titles:['Happy',
                  'Angry',
                  'Sad',
                  'Big Grin',
                  'Look Here',
                  'Bright Idea',
                  'Caution',
                  'Question',
                  'Cool!'],
          image_border_width:1,
          image_border_color:'red'
          });
</script></div><h1 style='float:right;'>Oooo, spinning!</h1><div style='clear:left'>
<script type='text/javascript'>
carousel({id:'carousel_7',
          border:'',
          size_mode:'carousel',
          width:287,
          height:35,
          sides:24,
          steps:5,
          speed:11,
          direction:'right',
          images:['http://www.codingforums.com/images/icons/icon7.gif',
                  'http://www.codingforums.com/images/icons/icon8.gif',
                  'http://www.codingforums.com/images/icons/icon3.gif',
                  'http://www.codingforums.com/images/icons/icon4.gif',
                  'http://www.codingforums.com/images/icons/icon5.gif',
                  'http://www.codingforums.com/images/icons/icon9.gif',
                  'http://www.codingforums.com/images/icons/icon10.gif',
                  'http://www.codingforums.com/images/icons/icon13.gif',
                  'http://www.codingforums.com/images/icons/icon12.gif',
                  'http://www.codingforums.com/images/icons/icon11.gif',
                  'http://www.codingforums.com/images/icons/icon2.gif',
                  'http://www.codingforums.com/images/icons/icon6.gif'],
          links: ['http://www.codingforums.com/',
                  'http://www.codingforums.com/',
                  'http://www.codingforums.com/',
                  'http://www.codingforums.com/'],
          titles:[],
          image_border_width:1,
          image_border_color:'blue'
          });
</script></div>
</div>
<script type='text/javascript'>
carousel({id:'Photos Courtesy of Dynamic Drive',
          border:'',
          size_mode:'image',
          width:138,
          height:225,
          sides:6,
          steps:23,
          speed:5,
          direction:'left',
          images:['http://www.dynamicdrive.com/dynamicindex14/photo1.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo2.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo3.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo4.jpg'],
          links: ['http://www.dynamicdrive.com/dynamicindex14/photo1.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo2.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo3.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo4.jpg'],
          titles:[],
          image_border_width:0,
          image_border_color:'blue'
          });
</script>
</body></html>

Yes, it's a whopping big closure! :) Any other comments/suggestions?

Edit: Now with vertical!
Speed parameter altered - now roughly equals carousel rpm.

Edit: New size_mode parameter! See posts below

WA 05-10-2005 06:50 PM

Very interesting! Can you quickly list the improvements or how it differs from the original version? I see that multiple copies of the script can be run on the same page...

Basscyst 05-10-2005 07:04 PM

That is really cool man. Good Job. :thumbsup:

Basscyst

Harry Armadillo 05-10-2005 07:15 PM

The biggest difference is the affect on the global-namespace. It uses no global variables, and only the one global function. This makes it absurdly unlikely that it will conflict with any other scripts on a page.

Mine doesn't use the body or window onload events. Again, making it unlikely to clash with other scripts and making installation easier.

This one let's you have a carousel with an arbitrary number of side; the DD script only allows 4/6/8/12 sides.

In mine, I've tried to precompute as much as possible. The movement is done with a very fast update of the images' rights/lefts and widths, using values stored an array. The DD script does the same expensive floating point calcutions over and over, every 50ms, and constantly changes the src's of it's image element (necessitating more extensive DOM updates).

What else did I do? Hmm...

WA 05-10-2005 07:42 PM

Definitely sounds like a step up from the original script. :) I'll test it some more, though do you have any objections to this script being possbily posted on Dynamic Drive? If not, please let me know the credits (ie: name, site URL) you wish to be displayed alongside script.

Thanks,

Harry Armadillo 05-10-2005 08:14 PM

I appreciate the offer of testing -- I whipped it out this morning in spare moments and have little doubt that a bug or two has escaped me.

I'm fine with it finding a home at Dynamic Drive. I compartmentalize my web presence, so credit to Harry Armadillo is enough and perhaps a link to the forums here.

Input on instructions/commenting would be highly useful. With my brain stuffed with the script's innermost secrets, its hard for me grasp what other people don't know but should. Take the previous sentence as an example of my explanation deficits....

WA 05-10-2005 08:17 PM

Thanks for the permission. It probably will be two weeks before the script is featured on Dynamic Drive. I'll test it out in the meantime, and if you do make any changes to the script on your own (ie: bug fixes), please simply edit the above script to include this change.

Thanks!

glenngv 05-11-2005 03:34 AM

Nice script!
 
There's an invalid argument error in IE. grey is different than gray unlike in FF. Actually, IE is inconsistent as lightgrey is correct and lightgray is wrong.
Code:

carousel({id:'carousel_2',
          border:'1px solid grey',

BTW, Is there any special reason why you used document.write instead of createElement?

Harry Armadillo 05-11-2005 08:20 AM

Grey, gray, bah! That's what I get for trying to save the extra tenth of a second a hex color would have needed. :( Thanks.

I used document.write so that the carousel div would be a child of whatever element is desired, without needing the person building the page to specify the parent. I could have used a placeholder div like the original, but wanted to make installation as simple as possible -- insert the main script in the head, insert a function call where you want the slideshow. No need to worry about editing around onload conflicts, no questions about which arguments apply to which slideshow when using multiple

Edit :: Thinking about the 'sticking the function call where ever you want' business made me realize something - it didn't fit very well into narrow columns. So...changes. Carousel slideshow, now featuring vertical action!

WA 05-11-2005 08:19 PM

Vertical option- very nice! BTW, what's the difference between "sides" and "steps" in the exposed parameters list?

I see this script runs in Opera 7 as well, which is great. Efficiency wise, Firefox seems to render it the slowest, especially with the 3 slideshows you have running at the same time.

Harry Armadillo 05-11-2005 09:27 PM

Yeah, it's odd how different browsers are faster at one thing, but slower at another. meh.

Sides controls the number of sides on the carousel. Four for a cube, etc. Odd numbers work, but look a little funny since I can't do perspective and the rotational axis isn't obvious/visible (something to work on). Since only the front of the carousel is shown, there will be sides/2 images on screen at a time.

Steps set how many intermediate steps are used in moving a picture one position forward. Say we had steps:16, then if picture-A is at the front, there would be 16 repositionings before its neighbor picture-B is in front. Too few steps will make the movement jerky, but will save processor power. More steps is more taxing, but smoother. Way too many steps will give a vibrating sort of look, due to rounding error and the finite size of a pixel.

I like steps*sides of around 100-140. Gives a decent balance of smoothness and processing load.

At the moment, speed doesn't take into account the number of steps (more steps will slow down the overall spin). I'm working on making the speed more independent; still trying to find a scheme I like.

Edit: The carousel will now spin at a revolutions per minute rate roughly equal to the speed parameter. Due to differences in processing load, the same speed with different numbers of steps will result in slightly different net speeds (I've tries to compensate but machine/browser variances matter).

WA 05-16-2005 02:37 AM

I've just tested this script some more. Some feedback:

1) Does the links[] array work at the moment? I tried inputting URLs, but the images remain unlinked.

2) In IE, users who have JS debugging turned on and misconfigure the script will be bombarded with errors. I'd recommend perhaps adding a line like:

window.onerror=function(){if (document.all){window.status='An error has occured'; return true}}

to the top of the script.

3) It's difficult to get the slideshow to show the images in their original, undistorted dimension without a lot of trial and error with the width/height parameters. I think a good idea may be to just ask for the true dimension of the images (making the assumption each one is the same size), and then based on sides and direction, display an image slideshow with the ideal dimensions.

I'm writing up the page for this script on DD, though may wait for the next revision when some of the above are solved before actually publishing it.

Thanks!

Harry Armadillo 05-16-2005 06:52 PM

The link array ought be working...are you getting any error messages? The examples in the last update didn't have links included, did you stick some in for yourself? I've added google links to the pair of cube examples, and also added the link-indicating hand/pointer mouse-cursor.

I'm loath to mask all errors -- it encourages the amateur webmaster to serve broken scripts and pages. Instead I've added checking for parameter validity and substitution of a default for an illegal value. The upper-left cube is now fed almost entirely bogus parameters, but still functions. Let me know if this is good enough -- I could still add some debuggin help or, eventually, the error masking.

I've added a new parameter/mode. size_mode:'image' makes the height and width parameters apply to the image (the overall heigh/width are then derived); size_mode:'carousel' (or any other non 'image' value) makes the height/width apply to the container div. The carousel with DynamicDrive images is done with size_mode:'image' as is one of the vertical wheels on the right.

Vladdy 05-17-2005 06:19 AM

Too bad all that content is unavailable to clients with disabled JS...

WA 05-19-2005 11:37 PM

Sorry for the delay, been very busy. I'll run some tests with the updated script early next week, and post more feedback if needed.

Harry Armadillo 05-19-2005 11:54 PM

No worries. Free and fun don't impose deadlines.

WA 05-23-2005 10:21 PM

I've gone ahead and posted the script on DD: http://www.dynamicdrive.com/dynamici.../carousel2.htm :) One thing I noticed is that in Opera 7, a vertical slideshow creates a huge gap at the bottom of the page; not sure about Opera 8 yet. Apart from that, looks great!

OutboundIndex 05-26-2005 09:51 PM

New window target in carousel slideshow
 
I tried out the Carousel Slide show here:

http://blog.fullscalecommerce.com/

Wondering how to make the links in the slide show open up in a new window.

I actually have all the slideshow code here:

http://blog.fullscalecommerce.com/portfolio.cfm and I "cfinclude" it into the main page. I tried a BASE target= in the head section but to no avail.

Thank you

davidjovan 05-26-2005 10:22 PM

I've been using the original carousel for quite some time now. This is such a millennium improvement.

One thing that I've always wanted was a way for you to be able
to click the link and it would pop you out of a frame. I've tried
adding the ' target="_top" ' parameter, but it just stays in the frame.

Maybe in the next revision. Just wanted to say wicked improvement. :thumbsup:

Harry Armadillo 05-26-2005 11:06 PM

Yeah, I wondered how long it would take before people wanted the links in new windows... :)

How much control do you want (versus how much it takes to set up the show)? Do you want the links to all open in in separate new windows? To be opened in single pop-up, where clicking a another link replaces the pop-up page? Mix-and-match?

Tell me your desires, then give me a couple days, and I'll (try to) make it happen.

davidjovan 05-27-2005 05:59 PM

I don't mind. I'll take the one where clicking another link replaces the pop-up page, if you can make it happen. Hell, why not throw everything in? :D :thumbsup:

www.badh.net

Harry Armadillo 05-29-2005 08:13 AM

Okay, new optional parameter lnk_base:"". lnk_base can be one of the standard link-targets '_self', '_parent', '_top' and '_blank', or it can be a frame/iframe path.name prepended with an underscore (so _pics for the in-page iframe named pics or _top.foo for a frame owned by the top frameset), or the name of a pop-up window. If no lnk_base is specified, a window named 'new' is used by default.

new optional parameter lnk_targets:[]. If you don't want all the image links to have the same target, individual targets can be assigned. A target here overrides the lnk_base target (if present). If an image's entry in the lnk_targets array is blank or missing, lnk_base or the default is used.

new optional parameter lnk_attr:[] Here you can specify the attributes to use for an image's pop-up window. If none are present, a regular sized window with all the toolbars, menus, etc. is used.

In addition, the bug where opera sometime had huge gaps below or left of the document's body has been fixed.

Sample page with updated carousel() function and a pair of examples to show how the new parameters in action:
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><title>Carousel Slideshow</title>
<script type='text/javascript'>
function carousel(params){
  if(!(params.width>0&&isFinite(params.width)))params.width=100;
  if(!(params.height>0&&isFinite(params.height)))params.height=100;
  if(!(params.sides>2&&isFinite(params.sides)))params.sides=4;
  if(!(params.steps>0&&params.steps<100&&isFinite(params.steps)))params.steps=20;
  if(!(params.speed>0&&isFinite(params.speed)))params.speed=8;
  if(!(params.image_border_width>=0&&isFinite(params.image_border_width)))params.image_border_width=0;
  if(isFinite(params.id)||!params.id)params.id='bad_id_given_'+Math.random();
 
  document.write("<div style='position:relative;overflow:hidden;' id='"+params.id.replace(/[^a-zA-Z0-9]+/g,'_')+"'></div>");
  var cdiv=document.getElementById(params.id.replace(/[^a-zA-Z0-9]+/g,'_'))
  cdiv.style.width=params.width+'px';
  cdiv.style.height=params.height+'px';
  cdiv.style.border=params.border;
  cdiv.style.position='relative';
  cdiv.style.overflow='hidden';
  cdiv.title=params.id;
   
  var counter=0,spinning=true,interval=Math.floor(60000/params.sides/params.steps/params.speed)-5;
  interval=isNaN(interval)?200:interval;
  var img_position=[],images=[],img_dimension=[];
  var img_index=params.images.length+1,img_index_cap=2*params.images.length;
  var faces=Math.ceil(params.sides/2), dimension, direction, targ, attr, faraway;

  function init(){
    if(params.direction=="left" || params.direction=="right"){
      direction=params.direction;
      dimension="width";
      }
    else if(params.direction=="top" || params.direction=="bottom"){
      direction=params.direction;
      dimension="height";
      }
    else {
      direction="left";
      dimension="width";
      }     
    faraway=(direction=="left"||direction=="top")?'-20000px':'20000px';
    cdiv.style[dimension]=params[dimension]/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)+'px';
    var img=new Image();
    img.style.position='absolute';
    img.style[direction]=faraway;
    img.style.width=params.width-2*params.image_border_width+'px';
    img.style.height=params.height-2*params.image_border_width+'px';
    img.style.border=(params.image_border_width||0)+'px solid '+params.image_border_color;
 
    for(var i=0;i<params.images.length;i++){
      images[i]=img.cloneNode(true);
      images[i].src=params.images[i];
      if(params.links&&params.links[i]&&params.links[i]!=''){
        targ=params.lnk_targets&&params.lnk_targets[i]||params.lnk_base||'new';
        if(targ=="_blank"){
          attr=(params.lnk_attr&&params.lnk_attr[i])?",'"+params.lnk_attr[i]+"'":"";
          images[i].onclick=new Function("window.open('"+params.links[i]+"','"+targ+"'"+attr+")");
          }
        else if(targ.substr(0,1)=="_"){
          images[i].onclick=new Function(targ.substr(1)+".location='"+params.links[i]+"'");
          }
        else{
          attr=(params.lnk_attr&&params.lnk_attr[i])?",'"+params.lnk_attr[i]+"'":"";
          images[i].onclick=new Function("var t='"+targ+"';if(window[t]){try{window[t].close()}catch(z){}}window[t]=window.open('"+params.links[i]+"',t"+attr+");window[t].focus()");
          }
        images[i].style.cursor=document.all?'hand':'pointer';
        }

      if(params.titles&&params.titles[i]&&params.titles[i]!='')
        images[i].title=params.titles[i];
      if(document.all)
        images[i].alt=images[i].title;
      images[i+params.images.length]=images[i];
      if(params.images.length==faces)
        images[i+2*params.images.length]=images[i];
      cdiv.appendChild(images[i]);
      }
 
    var face_size=params.size_mode=='image'?params[dimension]:params[dimension]*Math.sin(Math.PI/params.sides);
    var face_offset=params[dimension]*Math.cos(Math.PI/params.sides)/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)/2-.5;
    var pi_piece=2*Math.PI/params.steps/params.sides;
    for(i=0;i<=params.steps*faces;i++){
      img_dimension[i]=face_size*Math.sin(pi_piece*i);
      img_position[i]=(i<params.steps*params.sides/2)?Math.floor(params[dimension]/2/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)-face_offset*Math.cos(pi_piece*i)-img_dimension[i]/2)+'px':faraway;
      img_dimension[i]=img_dimension[i]-2*params.image_border_width>1?Math.ceil(img_dimension[i])-2*params.image_border_width+'px':'1px';
      }
    }
  init();

  cdiv.rotate = function(){
    setTimeout('document.getElementById("'+cdiv.id+'").rotate()',interval);
    if(!spinning) return;
    if(++counter>=params.steps){
      counter=0;
      if(++img_index>=img_index_cap)
        img_index=params.images.length;
      }
    images[img_index-faces].style[direction]=faraway;
    for(var i=faces-1;i>=0;i--){
      images[img_index-i].style[direction]=img_position[counter+i*params.steps];
      images[img_index-i].style[dimension]=img_dimension[counter+i*params.steps];
      }
    }
  cdiv.onmouseover=function(){
    spinning=false;
    }
  cdiv.onmouseout=function(){
    spinning=true;
    }
  setTimeout('document.getElementById("'+cdiv.id+'").rotate()',100);
  }
</script>
</head><body>
<div id='jake' style='width:180px;float:left;'>
<h4>Linkage</h4>All of these images will open a google search in single (reused) window.
<script type='text/javascript'>
carousel({id:'carousel_2',
          border:'',
          size_mode:'carousel',
          width:144,
          height:100,
          sides:4,
          steps:20,
          speed:8,
          direction:'right',
          images:['http://www.codingforums.com/images/icons/icon7.gif',
                  'http://www.codingforums.com/images/icons/icon8.gif',
                  'http://www.codingforums.com/images/icons/icon9.gif',
                  'http://www.codingforums.com/images/icons/icon10.gif',
                  'http://www.codingforums.com/images/icons/icon2.gif',
                  'http://www.codingforums.com/images/icons/icon3.gif',
                  'http://www.codingforums.com/images/icons/icon4.gif',
                  'http://www.codingforums.com/images/icons/icon5.gif',
                  'http://www.codingforums.com/images/icons/icon6.gif'],
          links: ['http://www.google.com/search?q=happy',
                  'http://www.google.com/search?q=angry',
                  'http://www.google.com/search?q=sad',
                  'http://www.google.com/search?q=big+grin',
                  'http://www.google.com/search?q=look+here',
                  'http://www.google.com/search?q=bright+idea',
                  'http://www.google.com/search?q=caution',
                  'http://www.google.com/search?q=question',
                  'http://www.google.com/search?q=cool'],
          lnk_base:'google',
          titles:['Happy',
                  'Angry',
                  'Sad',
                  'Big Grin',
                  'Look Here',
                  'Bright Idea',
                  'Caution',
                  'Question',
                  'Cool!'],
          image_border_width:1,
          image_border_color:'red'
          });
</script></div>
<div id='wendel' style="width:300px;float:right">
<h4>More Linkage</h4>Two photos share a single window, closing/reopening it with each click to allow the attributes to change. One photo opens in a _blank window, with another window added each click. The last photo opens in an iframe.
<script type='text/javascript'>
carousel({id:'Photos Courtesy of Dynamic Drive',
          border:'',
          size_mode:'image',
          width:140,
          height:225,
          sides:6,
          steps:20,
          speed:5,
          direction:'left',
          images:['http://www.dynamicdrive.com/dynamicindex14/photo1.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo2.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo3.jpg',
                  'http://www.dynamicdrive.com/dynamicindex14/photo4.jpg'],
          links:['http://www.dynamicdrive.com/dynamicindex14/photo1.jpg',
                'http://www.dynamicdrive.com/dynamicindex14/photo2.jpg',
                'http://www.dynamicdrive.com/dynamicindex14/photo3.jpg',
                'http://www.dynamicdrive.com/dynamicindex14/photo4.jpg'],
          lnk_base:'',
          lnk_targets:['photo',
                      'photo',
                      '_blank',
                      '_steve' ],
          lnk_attr:['width=200,height=300,top=200,menubar=yes',
                    'width=300,height=200,left=400,scrollbars=yes',
                    'width=150,height=250,left=300,top=100',
                    ''],
          titles:['Opens in \'photo\' window',
                  'Opens in \'photo\' window',
                  'Opens in blank window',
                  'Opens in iframe'],
          image_border_width:0,
          image_border_color:'blue'
          });
</script></div>
<iframe name='steve' style="margin-top:20px;width:300px;height:300px;border:0px solid white"></iframe>
</body></html>


davidjovan 05-31-2005 03:47 AM

Harry Armadillo! You get the friggin Nobel Peace Prize for 2k5. I can't believe you did it... Thank you very much...

I Salute you Sir!

WA 05-31-2005 07:45 AM

Hi:
For the updated code, I noticed the slideshow no longer pauses when the mouse is over it- any reason why this was removed? Personally I think it's a useful feature. :)

Harry Armadillo 05-31-2005 07:57 AM

That would be the fault of my spam-filters. :) When I post code, it gets sent out fine. But if I edit the post and am not paying attention, my spam-filters will chew up the code as it loads into the edit window and spit garbage back into the forums. Someday, when I'm not lazy, I'll reprogram that nonsense out.

Fixed/replaced with good code!

WA 05-31-2005 09:27 AM

Wow thanks for the quick fix. You've inspired me to go ahead and update the script on DD for it just as fast as well: http://www.dynamicdrive.com/dynamici.../carousel2.htm

Harry Armadillo 05-31-2005 09:43 AM

If only I was this responsive with real work. :D

Rad2 06-03-2005 03:55 AM

Need help please :-) simple for some, nightmare for me.
 
Hi, could someone give me a hint on how to correct this so it shows in the middle and at full banner size.

I just love effects, but cannot quiet get this one just where I like it.

http://traffic-cells.com/P1/launcha2.htm

as you can see its only showing like half the banner etc.

All I want is for it to show the full banner under the top table there all the rest works fine :-)

all help much appreciated and take it easy with code talk, I'm not that well in understanding the language.

Thanks
Rad2

Harry Armadillo 06-03-2005 09:12 AM

Where you have
Code:

<div align="center">
<script type='text/javascript'>
carousel({id:'carousel_3',

change it to
Code:

<div style='text-align:center;'>
<div style='text-align:left;width:468px;margin:auto;'>
<script type='text/javascript'>
carousel({id:'carousel_3',

And down a little lower,
Code:

  </script>
</div>
</body>

should become
Code:

  </script>
</div></div>
</body>


chareen 06-08-2005 10:15 PM

???
 
okay i'm kinda new at this whole java script thing... but i've been trying to do the carousel slideshow and it comes up blank.. here is what i paste ....please let me know what and where is it wrong...thank you...

<script type='text/javascript'>
function carousel(params){
if(!(params.width>0&&isFinite(params.width)))params.width=100;
if(!(params.height>0&&isFinite(params.height)))params.height=100;
if(!(params.sides>2&&isFinite(params.sides)))params.sides=4;
if(!(params.steps>0&&params.steps<100&&isFinite(params.steps)))params.steps=20;
if(!(params.speed>0&&isFinite(params.speed)))params.speed=8;
if(!(params.image_border_width>=0&&isFinite(params.image_border_width)))params.image_border_width=0;
if(isFinite(params.id)||!params.id)params.id='bad_id_given_'+Math.random();

document.write("<div style='position:relative;overflow:hidden;' id='"+params.id.replace(/[\r\n\t ]+/g,'_')+"'></div>");
var cdiv=document.getElementById(params.id.replace(/[\r\n\t ]+/g,'_'))
cdiv.style.width=params.width+'px';
cdiv.style.height=params.height+'px';
cdiv.style.border=params.border;
cdiv.style.position='relative';
cdiv.style.overflow='hidden';
cdiv.title=params.id;

var counter=0,spinning=true,interval=Math.floor(60000/params.sides/params.steps/params.speed)-5;
interval=isNaN(interval)?200:interval;
var img_position=[],images=[],img_dimension=[];
var img_index=params.images.length+1,img_index_cap=2*params.images.length;
var faces=Math.ceil(params.sides/2), dimension, direction;

function init(){
if(params.direction=="left" || params.direction=="right"){
direction=params.direction;
dimension="width";
}
else if(params.direction=="top" || params.direction=="bottom"){
direction=params.direction;
dimension="height";
}
else {
direction="left";
dimension="width";
}
cdiv.style[dimension]=params[dimension]/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)+'px';
var img=new Image();
img.style.position='absolute';
img.style[direction]='10000px';
img.style.width=params.width-2*params.image_border_width+'px';
img.style.height=params.height-2*params.image_border_width+'px';
img.style.border=(params.image_border_width||0)+'px solid '+params.image_border_color;

for(var i=0;i<params.images.length;i++){
images[i]=img.cloneNode(true);
images[i].src=params.images[i];
if(params.links&&params.links[i]&&params.links[i]!=''){
images[i].onclick=new Function("window.location='"+params.links[i]+"'");
images[i].style.cursor=document.all?'hand':'pointer';
}
if(params.titles&&params.titles[i]&&params.titles[i]!='')
images[i].title=params.titles[i];
images[i+params.images.length]=images[i];
if(params.images.length==faces)
images[i+2*params.images.length]=images[i];
cdiv.appendChild(images[i]);
}

var face_size=params.size_mode=='image'?params[dimension]:params[dimension]*Math.sin(Math.PI/params.sides);
var face_offset=params[dimension]*Math.cos(Math.PI/params.sides)/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)/2-.5;
var pi_piece=2*Math.PI/params.steps/params.sides;
for(i=0;i<=params.steps*faces;i++){
img_dimension[i]=face_size*Math.sin(pi_piece*i);
img_position[i]=(i<params.steps*params.sides/2)?Math.floor(params[dimension]/2/(params.size_mode=='image'?Math.sin(Math.PI/params.sides):1)-face_offset*Math.cos(pi_piece*i)-img_dimension[i]/2)+'px':'10000px';
img_dimension[i]=img_dimension[i]-2*params.image_border_width>1?Math.ceil(img_dimension[i])-2*params.image_border_width+'px':'1px';
}
}
init();

cdiv.rotate = function(){
setTimeout('document.getElementById("'+cdiv.id+'").rotate()',interval);
if(!spinning) return;
if(++counter>=params.steps){
counter=0;
if(++img_index>=img_index_cap)
img_index=params.images.length;
}
images[img_index-faces].style[direction]='20000px';
for(var i=faces-1;i>=0;i--){
images[img_index-i].style[direction]=img_position[counter+i*params.steps];
images[img_index-i].style[dimension]=img_dimension[counter+i*params.steps];
}
}
cdiv.onmouseover=function(){
spinning=false;
}
cdiv.onmouseout=function(){
spinning=true;
}
setTimeout('document.getElementById("'+cdiv.id+'").rotate()',200);
}
</script>
</head><body>
<div id=right_bar style='width:90px;float:right;'>
<h4>Vertical!</h4>
<script type='text/javascript'>
carousel({id:'carousel_0',
border:'',
size_mode:'image',
width:75,
height:75,
sides:4,
steps:8,
speed:7,
direction:'top',
images:['http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_DSC00024.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0009.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0008.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0007.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0006.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0005.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0004.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0003.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0002.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_Scan0001.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_100_0055.jpg',
'http://i5.photobucket.com/albums/y160/cpobleteporte/rnc/th_34SA3409.jpg'],
links: [],
titles:[],
image_border_width:2,
image_border_color:'black'
});
</script></div>



i actually want it to go horizontal...if you can e-mail me or something for the exact script i would greatly appreciate it... c_porte79@yahoo.com...

chareen 06-08-2005 10:18 PM

oh btw....here is the site i'm trying to put the slideshow in....
http://www.peoplefromguam.com/user.asp?id=22859

Harry Armadillo 06-09-2005 09:05 AM

The stuff in your first post worked fine for me. Changing from vertical to horizontal is simply a matter of changing

direction:'top',

to

direction:'left',

The problem is probably with your page. I was going to looking at your code, but when your page started popping up those annoying alert boxes, I killed the window. I also tried running it through W3's validator - here - but that failed.

I suggest posting in the html forum, get some help getting the page working working/valid, then try the carousel again.

chareen 06-09-2005 10:02 PM

im sorry...
 
okay ive removed the alet boxes.... pls take a look at it...

chareen 06-10-2005 02:13 AM

okay i fixed my page and tried to put the code again.. it just shows the word vertical on it.....

Harry Armadillo 06-10-2005 10:11 AM

I looked at it, the error I see immediately is
Code:

images:[<a href="http://i5.photobucket.com/albums/y160/cpobleteporte/1st%20album/100_0180.jpg" target="_blank"></a>,
you need to use just the image urls. Like
Code:

images:['http://i5.photobucket.com/albums/y160/cpobleteporte/1st%20album/100_0180.jpg',
Seriously though, you need to fix the rest of your HTML. I got the validator to look at it here. Of the 247 errors it found, a good 100 or so are serious. I designed my slideshow to tolerate a lot, but you've got way too many problems on that page. Fix the HTML, then we can get the carousel working. If the validator's output isn't enough to help you, start a thread in the HTML/CSS forum.

samohtwerdna 06-25-2005 11:23 PM

IE blank image??
 
Harry, or whomever can help.

I saw your image carousel on DD and thought I would give it a stab as my thumbnail slideshow. Works great in firefox - but everyones favorite IE decides to insert a blank image at the end of the carousel (very annoying)

How do I get rid of it??

Also wondered if you could give me some help sizing the images linked to the iframe. I want them all to come out 100% x 100% of the iframe. Any suggestions??

Thanks

Andy

Harry Armadillo 06-26-2005 12:10 AM

The blank image in IE is most likely from a typo in setting up the images. If you have a link to your page, I'll peek at the source and see if there's a problem.

Getting linked images to expand to the size of your iframe is simple (if tedious). Give each full-sized image its own basic page, setting the width and height in the <img src="fullsize.jpg"....> tag to match your iframe. Then link to those pages, instead of directly linking to the images.

Nils 06-26-2005 03:24 PM

@Harry: BIG RESPECT :thumbsup:

I really love that javascript. Wonderful programming. I just added it to my page:

http://www.4fr.de/vids/index.html

What do I have to change if I want it without the "Carousel" effect? Meaning that it just moves the images (not changing the imagesize) inside the given space?

Thanks for your inovations Harry. I love them!

Harry Armadillo 06-27-2005 03:02 AM

Thanks for the compliments, Nils. :)

The script is pretty specialized around the carousel-effect; it would require significant rewriting to convert it into a conveyer-belt slideshow. I've thought about making other versions (conveyer-belt, book-flip, fade-in, etc), but I'm currently buried in a PHP/MySQL project. Perhaps in a couple weeks...

In the meantime, this is good conveyer belt script. Heck, I've even used it!

Nils 06-27-2005 03:05 AM

thanks pal. I already included that one. Wonderful work!

All I need now is a perloader for my WMV files. Any suggestions ?

http://www.4fr.de/vids/videos.html

Would be a really big help.

I tried to convert them to SWF but the file sizes gets really big and the quality worse....so I need some kind of preloader infront of the WMV inside the iframe

Thanks in Advance

Nils


All times are GMT +1. The time now is 02:02 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.