Page 1 of 3 123 LastLast
Results 1 to 10 of 26

Thread: javascript image swap help

  1. #1
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript image swap help

    www.m-carroll.com

    I'm trying to get a simple image swap to change the main image when mouseover the thumbnails.

    Main images named: image001.jpg - image018.jpg

    Thumbnails named correspondantly: THUMB001.jpg-THUMB018.jpg

    Also I would like the thumbnail with the mousover to go black and white. I have created black and white thumbnail images named: THUMB001b.jpg - THUMB018b.jpg

    Any help appreciated

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    For the main part of that:

    http://www.dynamicdrive.com/dynamici...thumbnail2.htm

    To get the thumbs to change, just add to the onmouseover and add an onmouseout. The mouseover code for the above script is:

    Code:
    onmouseover="modifyimage('dynloadarea', 0)"
    so:

    Code:
    <img src="THUMB001.jpg" onmouseover="modifyimage('dynloadarea', 0);this.src='THUMB001b.jpg';" onmouseout="this.src='THUMB001.jpg';>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Having major probs figuring this out lol

    Any chance u could look at my source and tell me what to paste into what?

    Cheers - im a newbie at javascript

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Do your best effort (it doesn't have to work), put it on the web somewhere and I'll check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

  6. #6
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    Hmm... just try this, add it to your head:

    Code:
    <script type="text/javascript">
    function swap(orig) {
    var stmain = document.getElementById("main");
    stmain.setAttribute("src",orig.src)
    orig.onmouseout = function() {
    	stmain.setAttribute("src","http://www.m-carroll.com/stills/image011.jpg");
    	}
    }
    var directory = "stills"
    window.onload = function() {
    var obj = document.all ? document.all : document.getElementsByTagName("*");
    for (i = 0;i < obj.length;i++) {
    	if (obj[i].tagName == "IMG") {
    		var string = obj[i].src.substring(obj[i].src.indexOf(directory),obj[i].src.length).substring(0,6);
    		if (string == directory) {
    			obj[i].onmouseover = function() {
    				swap(this)
    				}
    			}
    		}
    	}
    }
    </script>
    - Mike

  7. #7
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Doesn't do anything...

  8. #8
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

  9. #9
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Brilliant - thanks for the hep your a legend

    what bits do I change so that the full size images can be shown?

  10. #10
    Join Date
    Jul 2006
    Location
    Canada
    Posts
    2,581
    Thanks
    13
    Thanked 28 Times in 28 Posts

    Default

    I'm not sure, do you have the large images saved as different files?
    - Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •