Advertisement
Guest User

Untitled

a guest
Aug 1st, 2012
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.     $.fn.hoverSprite = function(thisItem){
  3.         $(this).each(function(e){
  4.             var item =$(this),
  5.                 srcItem,
  6.                 widthItem,
  7.                 heightItem,
  8.                 imgItem = item.find("img"),
  9.                 idPage,
  10.                 MSIE = ($.browser.msie) && ($.browser.version <= 8);
  11.                
  12.             if(thisItem.onLoadWebSite == false || thisItem.onLoadWebSite == undefined){
  13.                 verificationPageHandler(); 
  14.                 $(window).bind("hashchange", verificationPageHandler);
  15.             }else{
  16.                 init();
  17.             }
  18.             function verificationPageHandler(){
  19.                 idPage = "#"+window.location.hash.substring(3, window.location.hash.length);
  20.                 if(idPage != "#"){
  21.                     if(item.parents(idPage).length != 0){
  22.                         setTimeout(init,700)
  23.                     }
  24.                 }
  25.             }          
  26.             function init(){
  27.                 srcItem = imgItem.attr("src");
  28.                 widthItem = imgItem.width();
  29.                 heightItem = imgItem.height();
  30.                 imgItem.remove();
  31.                 item.css({width:(widthItem), height:(heightItem/2),"display": "inline-block"});
  32.                 item.append("<div class='outIcon' style='position:absolute; display:block; width:"+widthItem+"px; height:"+(heightItem/2)+"px; background:transparent url("+srcItem+") no-repeat;'></div>");
  33.                 item.append("<div class='overIcon' style='position:absolute; display:block; width:"+widthItem+"px; height:"+(heightItem/2)+"px; background:transparent url("+srcItem+") 0 "+(-heightItem/2)+"px no-repeat;'></div>");
  34.                 item.hover(overHandler, outHandler);
  35.                
  36.                 if(!MSIE){
  37.                     item.find(".overIcon").animate({opacity:0}, 0)
  38.                 }else{
  39.                     item.find(".overIcon").css({"visibility":"hidden"})
  40.                 }
  41.                
  42.                 function overHandler(){
  43.                     if(!MSIE){
  44.                         $(this).find(".overIcon").stop().animate({opacity:1}, 600, "easeOutCubic")
  45.                         $(this).find(".outIcon").stop().animate({opacity:0}, 600, "easeOutCubic")
  46.                     }else{
  47.                         item.find(".overIcon").css({"visibility":"visible"})
  48.                         item.find(".outIcon").css({"visibility":"hidden"})
  49.                     }
  50.                    
  51.                 }
  52.                 function outHandler(){
  53.                     if(!MSIE){
  54.                         $(this).find(".overIcon").stop().animate({opacity:0}, 600, "easeOutCubic")
  55.                         $(this).find(".outIcon").stop().animate({opacity:1}, 600, "easeOutCubic")
  56.                     }else{
  57.                         item.find(".overIcon").css({"visibility":"hidden"})
  58.                         item.find(".outIcon").css({"visibility":"visible"})
  59.                     }
  60.                 }
  61.             }
  62.         })
  63.    
  64.     }
  65. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement