Results 1 to 3 of 3

Thread: Image change on click, changeback on click

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Image change on click, changeback on click

    Probably a simple script, if possible... I have a headache and can't think , but tbh I'm not very good at creating scripts, just editing and using them.

    I need a script that changes an image for example image1.gif when it's clicked to another image for example image2.gif, and when clicked again, back to image1.gif, and clicked again, image2.gif, click again image1.gif... i think you get my point. :P

    If anyone can offer me any help, I would be grateful, thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
      <script type="text/javascript">
        onload = function() {
          for(var i = 0, es = document.images, n = es.length, e = es[0]; i < n; e = es[++i]) {
            var m = e.className.match(/swap\((\w+), ([\w\/\.:&#37;]+)\)/);
            if(m)
              e['on' + m[1]] = (function(n) {
                return function() {
                  var oldsrc = this.src;
                  this.src = n;
                  n = oldsrc;
                };
              })(m[2]);
          }
          e = es = null;
        };
      </script>
    </head>
    <body>
      <p>
        <img alt="Something" src="image1.gif" class="swap(click, image2.gif)">
    You can use as many images as you like in that format (theoretically, I haven't tested it).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank You Very Much! Consider yourself a legend!

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
  •