473,785 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

display larger image on hover and stay inside viewport

Mike Kypriotis
37 New Member
So i found this script which does exactly what i want http://cssglobe.com/lab/tooltip/02/ (downloaded from its homepage at http://cssglobe.com/easiest-tooltip-...-using-jquery/) only problem is that the bigger image is not entirely shown in browser (aka viewport as i found here) if image too big or thumbnail near browser edges. After some search I modified it but still at hover it sometimes show outside viewport and then after mousemove the larger img get reposition correctly, original js
Expand|Select|Wrap|Line Numbers
  1. this.imagePreview = function(){ 
  2.         xOffset = 10;
  3.         yOffset = 30;
  4.         $("a.preview").hover(function(e){
  5.         this.t = this.title;
  6.         this.title = "";    
  7.         var c = (this.t != "") ? "<br/>" + this.t : "";
  8.         $("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");                                
  9.         $("#preview")
  10.             .css("top",(e.pageY - xOffset) + "px")
  11.             .css("left",(e.pageX + yOffset) + "px")
  12.             .fadeIn("fast");                        
  13.     },
  14.     function(){
  15.         this.title = this.t;    
  16.         $("#preview").remove();
  17.     }); 
  18.     $("a.preview").mousemove(function(e){
  19.         $("#preview")
  20.             .css("top",(e.pageY - xOffset) + "px")
  21.             .css("left",(e.pageX + yOffset) + "px");
  22.     });         
  23. };
  24.  
  25. // starting the script on page load
  26. $(document).ready(function(){
  27.     imagePreview();
  28. });
  29.  
and I changed the hover and mousemove to make this version
Expand|Select|Wrap|Line Numbers
  1. this.imagePreview = function(){ 
  2.         xOffset = 10;
  3.         yOffset = 20;
  4.         // these 2 variable determine popup's distance from the cursor
  5.         // you might want to adjust to get the right result
  6.     $(".preview").hover(function(kmouse){
  7.         this.t = this.title;
  8.         this.title = "";
  9.         src=this.src;   
  10.         if($(this).data("imgmode")=='1') 
  11.         {
  12.             src=src.replace("/thumbs",""); 
  13.         }
  14.         var c = (this.t != "") ? "<br/>" + this.t : "";
  15.         $("body").append("<p id='preview'><img src='"+ src +"' alt='Image preview' />"+ c +"</p>");                              
  16.  
  17.     },
  18.     function(){
  19.         this.title = this.t;    
  20.         $("#preview").remove();
  21.     }); 
  22.     $(".preview"). mousemove(function(kmouse){ 
  23.     var border_top = $(window).scrollTop(); 
  24.     var border_right = $(window).width(); 
  25.     var left_pos; var top_pos; var offset = 15; 
  26.     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");
  27.     }); 
  28.  
  29. };
  30. $(document).ready(function(){
  31.     imagePreview();
  32. });
  33.  
as you can see did some other minor changes like adjusting it for all elements with class preview not only a and also added a custom HTML5 tag data-imgmode which though plays no role in this problem just to meet my site demands.
Any ideas?
Aug 18 '13 #1
0 1571

Sign in to post your reply or Sign up for a free account.

Similar topics

1
7837
by: Jason Heydasch | last post by:
I was at 1800flowers.com today and when I clicked on an item to go to the product page for that item I noticed a script I have to find! If you hover over the small image of the product, a larger image pops up but it's not a separate windows, it seems like another layer. Check a page and hover your mouse over where it says "Enlarge Image"...
9
1966
by: Wally | last post by:
I am trying to display images from an Access 2000 database and I get an error "Invalid Parameter Used" when I execute the code line "picBLOB.Image = Image.FromStream(stmBLOBData)" in my Visual Basic .Net application. I have researched MSDN for help and found the example article 321900 (see below) and set up a test and everything works fine when I use SQL Server 2000 but when I modify the code and use data from Access 2000 using an...
2
1885
by: Jester | last post by:
I'm fairly new to asp.net. What is the syntax for the string to pull and image path from a DB and display that image based on the given path? I am trying to stay away from actually storing images in my DB and want to just store their paths there. I'd appreciate any help anyone can provide. Thanks. JESTER
3
4206
by: Sandi | last post by:
I have a simple problem: I have an Access database (images.mdb) that has 2 columns: one is the id if the picture (an integer) and one (column named picture) is a field of type OLE Object which contains an image (it can store jpg, bmp, gif, but I don't know what image is stored inside). I want to retrieve the picture stored in the database and identified by a given id and display it in a web page (.aspx). I write in Visual C#, but it does...
18
6523
by: Auto | last post by:
Hello, I would like to know how do display an image into a Gridview (ASP.NET 2.0) taken directly from a DataBase, NOT using an URL, like described in this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx06.asp I have NO URL, i have the binary image inside the DB, like the field "Photo" in the table "Employees" of the "NWIND.MDB" DataBase.
1
1837
by: rajbala.3399 | last post by:
Hai all, I need to get multiple image buttonsand wheni click on the image button it should display corresponding image on window and if i click another image button it is also display on same window without replacement of previously displayed image. For exampe,
4
1184
by: active | last post by:
If I place a Panel into a TableCell how do I display an image in the panel? Do I need to draw it in the Paint event or can I tell the Browser to do it? Thanks
1
3530
by: nanaalwi | last post by:
Hi, Currently I'm developing a software using VB.net that can grab an image using Matrox Morphis card and display it in a PictureBox. The software can grab the image already and display it in the form (Imports Matrox.ActiveMil). But the problem is I need to display the image in the PictureBox but I don't know how. The coding to grab the image is as follows: ActiveMILApplication = CreateObject("MIL.Application")
10
2540
by: dandyliondancer | last post by:
hola i figured out how to make an image appear next to a link when hovering by displaying it as a block and then using background:url div.menu a{ display:block; } div.menu a:hover{
5
3378
by: RuiT | last post by:
Hello, I'm uploading images to a folder and I want to display each new image on a web page every time it is saved in the folder. I can display the initial image, which is already in the folder, and I can also detect when a new image is saved into the folder but I don't know how to display the new images. I'm new to web development. Can somebody help me? Here's the code:
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10152
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10092
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8974
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.