LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2013, 04:27 AM   #1
Skyer
Member
 
Registered: Aug 2011
Posts: 113

Rep: Reputation: 6
web - image magnifier


Hello,
I'm trying to create image 'magnifier', as the one used on Amazon.
(example http://www.amazon.com/Fitbit-Wireles...ef=zg_bs_hpc_2).

I could not find it on google, and I'd also like to avoid using jquery and similar plugins if possible.

I'm not very experienced with javascript - I know it's going to involve onmouseover() and getElementById(), but I can't think of how to make just part of the image magnified - whole image would not be a problem.

Thank you for your help.

Last edited by Skyer; 06-13-2013 at 04:36 AM.
 
Old 07-10-2013, 06:03 PM   #2
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
For example:
Code:
<script>
function Zoom(aEvent)
  {
  var ZoomedImage = document.getElementById('ZommedImage');

  ZoomedImage.style.left = -(aEvent.clientX - aEvent.target.offsetLeft) * ZoomedImage.width / 50 + (300 / 2);
  ZoomedImage.style.top = -(aEvent.clientY - aEvent.target.offsetTop) * ZoomedImage.height / 50 + (300 / 2);
  }
</script>

<div style='border: 1px solid blue; width: 52px; height: 52px;'>
<img src='http://www.huntlogo.com/wp-content/uploads/2011/09/linux-logo-285x336.jpg' onmousemove='Zoom(event)' style='height: 50px; width: 50px;'>
</div>


<div style='position: relative; width: 300px; height: 300px; overflow: hidden; border: 1px solid red;'>
<img id='ZommedImage' style='position: absolute;' src='http://www.huntlogo.com/wp-content/uploads/2011/09/linux-logo.jpg'>
</div>
To "magnify" part of the image essential is external block element smaller than image with style "overflow: hidden;".

Last edited by eSelix; 07-10-2013 at 06:08 PM.
 
Old 07-14-2013, 03:10 AM   #3
Skyer
Member
 
Registered: Aug 2011
Posts: 113

Original Poster
Rep: Reputation: 6
Thank you for your answer,
I'm expecting it to be something like that, but I don't know how to 'select' just a part of the picture to be in the external block element.
 
Old 07-15-2013, 04:29 AM   #4
devnull10
Member
 
Registered: Jan 2010
Location: Lancashire
Distribution: Slackware Stable
Posts: 572

Rep: Reputation: 120Reputation: 120
Quote:
Originally Posted by Skyer View Post
but I don't know how to 'select' just a part of the picture to be in the external block element.
You don't need to, you're just shifting the position of the larger image around in its container. The "overflow:hidden" deals with keeping it "in the box".
 
Old 07-15-2013, 08:01 AM   #5
Skyer
Member
 
Registered: Aug 2011
Posts: 113

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by devnull10 View Post
You don't need to, you're just shifting the position of the larger image around in its container. The "overflow:hidden" deals with keeping it "in the box".
So how do I get the position of the mouse in relation to picture, so I know how much should I shift the big one?
 
Old 07-15-2013, 05:09 PM   #6
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Did you saw my code? There are three lines of simple javascript code to compute what you want. To get X and Y position of mouse pointer you can use "aEvent.clientX" and "aEvent.clientY" from mousemove event. Then you shift it by offset of small image and multiply by scale (ZoomedImage.width / 50) width of big image divided by width of small image, and then shift by half of big image, to move big image to center.

Last edited by eSelix; 07-16-2013 at 02:24 PM.
 
Old 07-16-2013, 05:03 AM   #7
Skyer
Member
 
Registered: Aug 2011
Posts: 113

Original Poster
Rep: Reputation: 6
Quote:
Originally Posted by eSelix View Post
Did you saw my code? There are three lines of simple javascript code to compute what you want. To get X and Y position of mouse pointer you can use "aEvent.clientX" and "aEvent.clientY" from mousemove event. Then you shift it by offset of small image and multiply by scale (ZoomedImage.width / 50 width of big image divided by width of small image and then shift by half of big image, to move big image to center.
Whoa, for some reason, I didn't see the code at all - I thought you're just vaguely referring to the solution. Thanks, I'll check it out.

Last edited by Skyer; 07-16-2013 at 05:05 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Making mouse-clicks work in Virtual-Magnifier ajaygarg Linux - Desktop 3 11-04-2012 07:26 AM
I want to download web image using wget or something moldycake Linux - General 4 07-13-2012 04:13 AM
where is the magnifier on latest ubuntu? skybright13 Ubuntu 1 08-23-2007 03:22 AM
Configuring Gnopernicus Magnifier kaplan71 Fedora 0 12-01-2005 11:12 AM
XWindows and Imlib and circular magnifier JohnCain Programming 0 08-26-2004 08:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration