Difference between revisions of "JQuery"
From Wikicliki
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | == jquery image hover == | |
+ | |||
+ | this [http://peps.ca/blog/easy-image-rollover-script-with-jquery/ image rollover] only requires you to apply the class ro to the image. it will swap in _o into the file name for an easy image swap using jquery. | ||
+ | |||
+ | <pre> | ||
+ | <script type="text/javascript"> | ||
+ | $(document).ready( function() | ||
+ | { | ||
+ | PEPS.rollover.init(); | ||
+ | }); | ||
+ | |||
+ | PEPS = {}; | ||
+ | |||
+ | PEPS.rollover = | ||
+ | { | ||
+ | init: function() | ||
+ | { | ||
+ | this.preload(); | ||
+ | |||
+ | $(".ro").hover( | ||
+ | function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); }, | ||
+ | function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); } | ||
+ | ); | ||
+ | }, | ||
+ | |||
+ | preload: function() | ||
+ | { | ||
+ | $(window).bind('load', function() { | ||
+ | $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); }); | ||
+ | }); | ||
+ | }, | ||
+ | |||
+ | newimage: function( src ) { return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_o' + src.match(/(\.[a-z]+)/)[0]; }, | ||
+ | oldimage: function( src ){ return src.replace(/_o/, ''); } | ||
+ | }; | ||
+ | </script> | ||
+ | </pre> | ||
== See Also == | == See Also == | ||
− | [[jquery | + | *[http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery jQuery] |
+ | *[http://www.noupe.com/tutorial/51-best-of-jquery-tutorials-and-examples.html] | ||
+ | *[http://jquery.lukelutman.com/plugins/flash/example-text-replacement.html uses a custom flash movie for the font] | ||
+ | *[[jQuery Sandbox]] |
Latest revision as of 14:01, 10 December 2009
jquery image hover
this image rollover only requires you to apply the class ro to the image. it will swap in _o into the file name for an easy image swap using jquery.
<script type="text/javascript"> $(document).ready( function() { PEPS.rollover.init(); }); PEPS = {}; PEPS.rollover = { init: function() { this.preload(); $(".ro").hover( function () { $(this).attr( 'src', PEPS.rollover.newimage($(this).attr('src')) ); }, function () { $(this).attr( 'src', PEPS.rollover.oldimage($(this).attr('src')) ); } ); }, preload: function() { $(window).bind('load', function() { $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', PEPS.rollover.newimage( $(this).attr('src') ) ); }); }); }, newimage: function( src ) { return src.substring( 0, src.search(/(\.[a-z]+)/) ) + '_o' + src.match(/(\.[a-z]+)/)[0]; }, oldimage: function( src ){ return src.replace(/_o/, ''); } }; </script>