Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Peter Cooperx http://www.petercooper.co.uk/

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Ultra simple Prototype.js AJAX example

Taken from the great Amy Hoy.

   1  <h2>ajax replacing link</h2>
   2  <a href="backend.php?return=time" 
   3     onclick="new Ajax.Updater('testdiv', 'backend.php?return=time',
   4     {asynchronous:true, evalScripts:true }); return false;">
   5  This link updates a line</a>
   6  <div id="testdiv"></div>


With no JavaScript turned on, it'll go to the normal URL. Without, it'll do an XMLHTTPRequest and put the result in #testdiv.

Miniature slideshow for DIVs using Scriptaculous

   1  <div id="slideshow1" class="slide"><div>frame 1</div></div>
   2  <div id="slideshow2" class="slide" style="display: none"><div>frame 2</div></div>
   3  <div id="slideshow3" class="slide" style="display: none"><div>frame 3</div></div>
   4  <div id="slideshow4" class="slide" style="display: none"><div>frame 4</div></div>
   5  
   6  <script type="text/javascript">
   7      
   8      start_slideshow(1, 4, 2000);
   9      
  10      function start_slideshow(start_frame, end_frame, delay) {
  11          setTimeout(switch_slides(start_frame,start_frame,end_frame, delay), delay);
  12      }
  13                              
  14      function switch_slides(frame, start_frame, end_frame, delay) {
  15          return (function() {
  16              Effect.Fade('slideshow' + frame);
  17              if (frame == end_frame) { frame = start_frame; } else { frame = frame + 1; }
  18              setTimeout("Effect.Appear('slideshow" + frame + "');", 850);
  19              setTimeout(switch_slides(frame, start_frame, end_frame, delay), delay + 850);
  20          })
  21      }
  22  
  23  </script>
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS