jquery - display larger image on hover and stay inside viewport -


so found script want http://cssglobe.com/lab/tooltip/02/ (downloaded homepage @ http://cssglobe.com/easiest-tooltip-and-image-preview-using-jquery/) problem bigger image not entirely shown in browser (aka viewport found here) if image big or thumbnail near browser edges. after search modified still @ hover show outside viewport , after mousemove larger img reposition correctly, original js

this.imagepreview = function(){          xoffset = 10;         yoffset = 30;         $("a.preview").hover(function(e){         this.t = this.title;         this.title = "";             var c = (this.t != "") ? "<br/>" + this.t : "";         $("body").append("<p id='preview'><img src='"+ this.href +"' alt='image preview' />"+ c +"</p>");                                         $("#preview")             .css("top",(e.pagey - xoffset) + "px")             .css("left",(e.pagex + yoffset) + "px")             .fadein("fast");                             },     function(){         this.title = this.t;             $("#preview").remove();     });      $("a.preview").mousemove(function(e){         $("#preview")             .css("top",(e.pagey - xoffset) + "px")             .css("left",(e.pagex + yoffset) + "px");     });          };  // starting script on page load $(document).ready(function(){     imagepreview(); }); 

and changed hover , mousemove make version

this.imagepreview = function(){          xoffset = 10;         yoffset = 20;         // these 2 variable determine popup's distance cursor         // might want adjust right result     $(".preview").hover(function(kmouse){         this.t = this.title;         this.title = "";         src=this.src;            if($(this).data("imgmode")=='1')          {             src=src.replace("/thumbs","");          }         var c = (this.t != "") ? "<br/>" + this.t : "";         $("body").append("<p id='preview'><img src='"+ src +"' alt='image preview' />"+ c +"</p>");                                    },     function(){         this.title = this.t;             $("#preview").remove();     });      $(".preview"). mousemove(function(kmouse){      var border_top = $(window).scrolltop();      var border_right = $(window).width();      var left_pos; var top_pos; var offset = 15;      if(border_right - (offset *2) >= $("#preview").width() + kmouse.pagex){ left_pos = kmouse.pagex+offset; } else{ left_pos = border_right-$("#preview").width()-offset; } if(border_top + (offset *2)>= kmouse.pagey - $("#preview").height()){ top_pos = border_top +offset; } else{ top_pos = kmouse.pagey-$("#preview").height()-offset; } $("#preview").css({left:left_pos, top:top_pos}).fadein("fast");     });   }; $(document).ready(function(){     imagepreview(); }); 

as can see did other minor changes adjusting elements class preview not , added custom html5 tag data-imgmode though plays no role in problem meet site demands.

first post here, still beginner js/jquery stuff hope gave u guys info u need :)


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -