/ Published in: jQuery
_off を _on ã«ç½®æ›ã—ã¦ãƒãƒ¼ãƒ«ã‚ªãƒ¼ãƒãƒ¼
_on ç”»åƒã‚’プレãƒãƒ¼ãƒ‰
_on ç”»åƒã‚’プレãƒãƒ¼ãƒ‰
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function(){ $('.onoff img').each(function(ev){ preload_img(this); $(this).mouseover(function(ev){ img_on(ev.target); }).mouseout(function(ev){ img_off(ev.target); }); }); }); function img_on(tgt){ var src=$(tgt).attr('src'); var newsrc=src.replace("_off","_on"); $(tgt).attr('src',newsrc); } function img_off(tgt){ var src=$(tgt).attr('src'); var newsrc=src.replace("_on","_off"); $(tgt).attr('src',newsrc); } function preload_img(tgt){ var src=$(tgt).attr('src'); var newsrc=src.replace("_off","_on"); $('<img>').attr('src', newsrc); }