/    Sign up×
Community /Pin to ProfileBookmark

resizing images in the slideshow javascript?

Hi: I am using the javascript at [url]http://javascript.internet.com/miscellaneous/image-slideshow.html[/url] with a minor modification (shown in red) to create a slideshow. This works perfect if all my images are of the same size. But when I rotate a image by 90 degrees and include that image it shows up as a streched image. What I can I do in the script to change the size for each image.

=====================

<!– TWO STEPS TO INSTALL IMAGE SLIDESHOW:

  • 1. Copy the coding into the HEAD of your HTML document

  • 2. Add the last code into the BODY of your HTML document –>
  • <!– STEP ONE: Paste this code into the HEAD of your HTML document –>

    <HEAD>

    <SCRIPT LANGUAGE=”JavaScript”>
    <!– Original: Ricocheting ([email protected]) –>
    <!– Web Site: [url]http://www.ricocheting.com[/url] –>

    <!– This script and many more are available free online at –>
    <!– The JavaScript Source!! [url]http://javascript.internet.com[/url] –>

    <!– Begin
    var rotate_delay = 5000; // delay in milliseconds (5000 = 5 secs)
    current = 0;
    function next() {
    if (document.slideform.slide[current+1]) {
    document.images.show.src = document.slideform.slide[current+1].value;
    document.slideform.slide.selectedIndex = ++current;
    }
    else first();
    }
    function previous() {
    if (current-1 >= 0) {
    document.images.show.src = document.slideform.slide[current-1].value;
    document.slideform.slide.selectedIndex = –current;
    }
    else last();
    }
    function first() {
    current = 0;
    document.images.show.src = document.slideform.slide[0].value;
    document.slideform.slide.selectedIndex = 0;
    }
    function last() {
    current = document.slideform.slide.length-1;
    document.images.show.src = document.slideform.slide[current].value;
    document.slideform.slide.selectedIndex = current;
    }
    function ap(text) {
    document.slideform.slidebutton.value = (text == “Stop”) ? “Start” : “Stop”;
    rotate();
    }
    function change() {
    current = document.slideform.slide.selectedIndex;
    document.images.show.src = document.slideform.slide[current].value;
    }
    function rotate() {
    if (document.slideform.slidebutton.value == “Stop”) {
    current = (current == document.slideform.slide.length-1) ? 0 : current+1;
    document.images.show.src = document.slideform.slide[current].value;
    document.slideform.slide.selectedIndex = current;
    window.setTimeout(“rotate()”, rotate_delay);
    }
    }
    // End –>
    </script>
    </HEAD>

    <!– STEP TWO: Copy this code into the BODY of your HTML document –>

    <BODY>

    <center>
    <form name=slideform>
    <table cellspacing=1 cellpadding=4 bgcolor=”#000000″>
    <tr>
    <td align=center bgcolor=”white”>
    <b>Image Slideshow</b>
    </td>
    </tr>
    <tr>
    <td align=center bgcolor=”white” width=200 height=150>
    <img src=”cart.gif” name=”show” [COLOR=red]HEIGHT=420 WIDTH=590[/COLOR]>
    </td>
    </tr>
    <tr>
    <td align=center bgcolor=”#C0C0C0″>
    <select name=”slide” onChange=”change();”>
    <option value=”cart.gif” selected>Cart
    <option value=”aat.gif”>AAT
    <option value=”boat.gif”>Boat
    <option value=”enterprise.gif”>Enterprise
    <option value=”ewing.gif”>E-Wing
    <option value=”f18.gif”>F-18
    <option value=”klingon.gif”>Klingon
    <option value=”landingcraft.gif”>Landing Craft
    <option value=”hoverracer.gif”>Hover Racer
    <option value=”sith.gif”>Sith
    </select>
    </td>
    </tr>
    <tr>
    <td align=center bgcolor=”#C0C0C0″>
    <input type=button onClick=”first();” value=”|<<” title=”Beginning”>
    <input type=button onClick=”previous();” value=”<<” title=”Previous”>
    <input type=button name=”slidebutton” onClick=”ap(this.value);” value=”Start” title=”AutoPlay”>
    <input type=button onClick=”next();” value=”>>” title=”Next”>
    <input type=button onClick=”last();” value=”>>|” title=”End”>
    </td>
    </tr>
    </table>
    </form>
    </center>

    <p><center>
    <font face=”arial, helvetica” size=”-2″>Free JavaScripts provided<br>
    by <a href=”http://javascriptsource.com”>The JavaScript Source</a></font>

    </center><p>
    =============

    Thanks
    Ray

    to post a comment
    JavaScript

    12 Comments(s)

    Copy linkTweet thisAlerts:
    @JPnycSep 15.2004 — Of course it does. You set a height and width on the img tag. Any pic shown will conform to those dimensions. Don't set a height or width, and make the pics the size you want them to display at. Then all will be well.
    Copy linkTweet thisAlerts:
    @rsmith967authorSep 15.2004 — Dunsel: thanks. If I donot use that line, some images are large and as a result have to use the scroll bar to view the complete image. Is there a way to resize the image during the slideshow for some pictures?

    Thanks

    Ray
    Copy linkTweet thisAlerts:
    @JPnycSep 15.2004 — Resize the imgs themselves. Displaying a pic that's larger than you need is a waste of bandwidth and coding time. Open them in a photo editor, and make them the size you need them to display at.
    Copy linkTweet thisAlerts:
    @VladdySep 15.2004 — Separate content from presentation from functionality: www.klproductions.com/klslideshow.html

    ?
    Copy linkTweet thisAlerts:
    @Warren86Sep 15.2004 — .
    Copy linkTweet thisAlerts:
    @JPnycSep 15.2004 — The problem appears to be that the pics are not all the same dimensions[I]proportionally.[/I] Changing them to the same dimensions dynamically will not change this. What he needs to do is make the pics themselves the proper dimension. The page will load faster, and there'll be no distorted display.
    Copy linkTweet thisAlerts:
    @Warren86Sep 15.2004 — .
    Copy linkTweet thisAlerts:
    @Warren86Sep 15.2004 — .

    [upl-file uuid=c16e57d1-0243-4f63-929b-30ebc6b1537e size=495B]reset&rename.zip[/upl-file]
    Copy linkTweet thisAlerts:
    @garek007Sep 17.2004 — Hi,

    I was reading this forum and this looks like something I could use help with too. Please help me in any way you can. I have a three frame layout. I created an image gallery through photoshop. It writes the frameset. I bring up my images from the index frame in the mainFrame. Problem is my resize script. It works okay, but I think it's moving too fast for the browser. Sometimes when I click the left index, the mainFrame goes blank I right click and view source and it is still calling the correct image but it just doesn't show. When I click that same thumbnail again, it shows up. My script is below. It's called by an onClick="swapImage()"

    function swapImage(whichImage){

    loadImage = new Image();
    loadImage.src = whichImage.toString();



    parent.mainFrame.document.images.mainImage.width = loadImage.width;
    parent.mainFrame.document.images.mainImage.height = loadImage.height;


    parent.mainFrame.document.images.mainImage.src = whichImage; //swaps the image

    var imageWidth = loadImage.width;
    var imageHeight = loadImage.height;

    if (imageWidth > imageHeight) {//document is landscape
    var ah = parent.mainFrame.document.body.clientWidth - 30;
    parent.mainFrame.document.images.mainImage.width = ah;
    newHeight = (imageHeight*ah)/imageWidth;
    parent.mainFrame.document.images.mainImage.height = newHeight;
    } else {

    var ah = parent.mainFrame.document.body.clientHeight - 30;
    parent.mainFrame.document.images.mainImage.height = ah;
    newWidth = (imageWidth*ah)/imageHeight;
    parent.mainFrame.document.images.mainImage.width = newWidth;
    }







    }
    Copy linkTweet thisAlerts:
    @JPnycSep 17.2004 — You didn't post anything that assigns a src to an img tag.
    Copy linkTweet thisAlerts:
    @JesusWaffleSep 18.2004 — Any image you resize with HTML will invariably look hideous. You just need to resize the images in Photoshop or something. Sorry.
    Copy linkTweet thisAlerts:
    @JesusWaffleSep 18.2004 — Any image you resize with HTML will invariably look hideous. You just need to resize the images in Photoshop or something. Sorry.
    ×

    Success!

    Help @rsmith967 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...