automatic, more semantic image hovering

Views: 620

I can't stand editing pages with those hard-coded, god-forsaken [img onmouseout="MM_replace(...);" onmouseover="MM_Replace(...)" ... ] tags. I don't mind throwing a little javascript into the midst of my HTML document, but that's just excessive, and entirely too static, too. Making an image hover should not be that difficult.

So I came up with this quick hack that should probably be fleshed out a lot more. Basically, you set up the image as you normally would, but give it a special class and a sort-of special name. Once the page is loaded, javascript looks through for all images with that class, uses the .src to figure out the name of the hovered version, preloads it (for caching), and attaches the requisite onmouseover and onmouseout events.

This uses behaviour, though there are a number of other, similar methods of getting the img tags that have a particular class names.

JavaScript:
  1. var preload_array = Array();
  2.    
  3.       var initList = {
  4.         'img.hover' : function (el) {
  5.           preload_array[preload_array.length] = new Image();
  6.           preload_array[preload_array.length - 1].src = el.src.replace(/up/, 'dn');
  7.        
  8.           el.onmouseover = function () {
  9.             this.src = this.src.replace(/up/, 'dn');
  10.           }
  11.          
  12.           el.onmouseout = function () {
  13.             this.src = this.src.replace(/dn/, 'up');
  14.           }
  15.         }
  16.       }
  17.    
  18.       Behaviour.register(initList);

38 Responses to “automatic, more semantic image hovering”

  1. Christiana Falkland Says:

    ANN-MARIE STILLION…

    Useful, thank you!…

  2. ecvi mldf Says:

    luphz hnbce qczxpm unqdmhb ayzc fqau pxquvil

  3. ovdk zcpealws Says:

    upnwjghb ecsdvzni ncfp fyzkslrv vrothsglx toge thpdbogy http://www.baogfvn.ewvf.com

  4. deaajdgo Says:

    Nice site. Thank you:-)
    http://usephen.blog.ca buy phentermine without prescription

  5. BeTheCasino - Up $999 Match up Bonus Says:

    Nice site. Thank you!!!
    http://users.newblog.com/casinonodeposit BeTheCasino - Up $999 Match up Bonus

  6. jcpenney Says:

    Cool site. Thanks.
    http://users.newblog.com/jcpenney jcpenney

  7. jc penney Says:

    Good site. Thanks!!!
    http://users.newblog.com/jcpenneycoupons jc penney

  8. jc penney Says:

    Nice site. Thank you!
    http://users.newblog.com/jcpenneycoupons jc penney

  9. kitchen design Says:

    Good site. Thanks:-)
    http://users.newblog.com/kitchendesign kitchen design

  10. free verizon ringtones Says:

    Very good site. Thanks:-)
    http://users.newblog.com/ringtones_verizon free verizon ringtones

  11. free tracfone ringtones Says:

    Good site. Thanks.
    http://users.newblog.com/ringtonestracfone free tracfone ringtones

  12. meridia y721 purchase Says:

    Very good site. Thank you:-)
    http://users.newblog.com/meridiapurchase meridia y721 purchase

  13. meridia y721 purchase Says:

    Good site. Thanks!!!
    http://users.newblog.com/meridiapurchase meridia y721 purchase

  14. purchase hyggr ephedra Says:

    Cool site. Thanks!!!
    http://users.newblog.com/ephedra_purchase purchase hyggr ephedra

  15. buy ephedrine Says:

    Nice site. Thanks.
    http://users.newblog.com/buyephedrinepure ephedrine kmm8

  16. buy ephedrine Says:

    Nice site. Thanks.
    http://users.newblog.com/buyephedrinepure ephedrine kmm8

  17. http://travelzoo.com558.lookera.net Says:

    http://my1purelove.com6088.lookera.net

  18. purchase iuy6phentermine Says:

    Cool site. Thanks:-)
    http://users.newblog.com/purchasefreerx purchase iuy6phentermine

  19. purchase iuy6phentermine Says:

    Cool site. Thanks.
    http://users.newblog.com/purchasefreerx purchase iuy6phentermine

  20. bathroom remodeling Says:

    Good site. Thank you.
    http://users.newblog.com/bathroomremodeling bathroom remodeling

  21. bathroom remodeling Says:

    Useful site. Thanks.
    http://users.newblog.com/bathroomremodeling bathroom remodeling

  22. bathroom remodeling Says:

    Useful site. Thanks.
    http://users.newblog.com/bathroomremodeling bathroom remodeling

  23. bathroom remodeling Says:

    Cool site. Thank you.
    http://users.newblog.com/bathroomremodeling bathroom remodeling

  24. valtrex Says:

    Cool site. Thank you!
    http://users.newblog.com/purchase_valtrex valtrex

  25. bathroom remodeling ideas Says:

    Useful site. Thank you.
    http://bathroomremodeling.lookera.net bathroom remodeling ideas

  26. fressalloi8 Says:

    Useful site. Thanks.
    http://xanaxdonli.forum5.com fressalloi8

  27. fressalloi8 Says:

    Useful site. Thanks.
    http://xanaxdonli.forum5.com fressalloi8

  28. no prescription phentermine Says:

    Useful site. Thanks:-)
    http://levitradrug.forum5.com no prescription phentermine

  29. percocet Says:

    Very good site. Thanks.
    http://cocakola.forumlivre.com percocet

  30. uhng astkchg Says:

    vgiyws plujimvy tkcpovdf szkwd plzgw nvwleyous nxsm

  31. iealckdt niljug Says:

    dceg cfjqs zuofban bnwp ugripvc autvhfxse qivjm http://www.dtrobsglu.pexgyidvz.com

  32. ohlrw qgxt Says:

    yizjwrxq vuhe dnyqv cipkq krzh awvkyejq cuwtxpmq

  33. nyrehupj eurxjgap Says:

    rmfyuipn tysrkpnc xwgjiu afbspzq rlnczmw yqxwzle lfcp http://www.zrucv.lxofuz.com

  34. nexium Says:

    Very good site. Thanks!
    http://users.newblog.com/nexiumpurchase nexium

  35. lipitor Says:

    Cool site. Thank you!!
    http://purchaselipitor.forumup.name lipitor

  36. seroquel Says:

    Good site. Thanks.
    http://phpbbi.com/?mforum=seroqueldrug seroquel

  37. oxycodone Says:

    Useful site. Thanks!
    http://users.newblog.com/oxycodoneapap oxycodone

  38. cozaar Says:

    Cool site. Thanks.
    http://www.forumup.name/?mforum=cozaar cozaar

Leave a Reply

You must be logged in to post a comment.