Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8226131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:39:31+00:00 2026-06-07T15:39:31+00:00

Exactly 50px, to be precise. I know it’s in the code somewhere, but I

  • 0

Exactly 50px, to be precise. I know it’s in the code somewhere, but I think i’ve been staring at it for too long.

Backstory: I’m making a simple jQuery plugin which will add a magnifying lens effect when hovering over images. It was working fine, then I added some code, and it started acting odd when entering from the top of the image. I used firebug to see if there was a difference between the top offset of the image and the pageY value of the cursor and there was.

In the link below you can see that moving in from above it doesn’t activate on time.

Code:

update: function(event) {
    img.stop(); // To stop the image from constantly animating
    img.lens.stop(); // Same for the lens
    img.lens.leftmax = img.width + img.left;
    img.lens.topmax = img.height + img.top;

    img.lens.x = event.pageX - (vars.size / 2);
    img.lens.y = event.pageY - (vars.size / 2);

    img.lens.css({
        left: img.lens.x + 'px',
        top: img.lens.y + 'px'
    });

    console.log(img.top + ' : ' + event.pageY);

    if (event.pageX >= img.lens.leftmax || event.pageY >= img.lens.topmax || event.pageX <= img.left || event.pageY <= img.top) {

        img.lens.hide(); // Hide lens
        if (options.caption) {
            img.lens.caption.hide();
        } // Hide Caption
        if (options.overlay) {
            methods.nooverlay();
        }

        // API Callback Exit
        vars.onexit(img, img.lens);
    } else {
        // API Callback on entering
        vars.onenter(img, img.lens);

        if (options.overlay) {
            methods.overlay();
        }

        methods.doMath(event); // Recalculate pos
        img.lens.show(); // Show lens
        img.lens.css({
            backgroundPosition: img.lens.bgleft + 'px ' + img.lens.bgtop + 'px'
        }); // Assign coordinates
        if (options.caption) {
            img.lens.caption.show(); // Show caption
            img.lens.caption.x = img.lens.x + ((vars.size - img.lens.caption.outerWidth()) / 2); // Center caption
            img.lens.caption.css({
                left: img.lens.caption.x + 'px',
                top: img.lens.y + vars.size + 'px'
            }); // Assign coordinates
        }
    }
},

doMath: function(event) {
    img.wr = img.Owidth / img.width;
    img.hr = img.Oheight / img.height;

    img.lens.bgleft = String(((event.pageX - img.left) * img.wr - vars.size / 2) * (-1));
    img.lens.bgtop = String(((event.pageY - img.top) * img.hr - vars.size / 2) * (-1));
},​

These are the main functions (part of a map) that make the hover action work and where i think the problem should lie. The code is pretty long, so for the sake of readability i’ll add a link to where i’m hosting the page in case you want to look at the full plugin code.

Link removed

Where am I going wrong?

EDIT:

So apparently the cause of the problem is a floating span element that is nested in a sibling of the parent, of the parent tag of the image:

    <div class="header">
        <!-- This span tag -->
        <span class="note">&rarr; If you're using IE8 or lower, you will see a square lens</span>
        <h1>jQuery Images Lens Preview</h1>
        <span><i>The most customizable zoom tool there is.</i> <a href="#">GET IT NOW!</a></span>
        <div style="clear: both;"></div>
   </div>

    <div class="example">
        <div class="desc">
             <h3>Demonstration #1 - Basic Usage</h3>
             <pre>$('img.basic').superLens();</pre>
        </div>
        <div class="theimages">
            <img src="images/demo_img1.jpg" width="214" height="320" class="basic" />
            <img src="images/demo_img2.jpg" width="214" height="320" class="basic" />
        </div>
        <div style="clear: both;"></div>
    </div>

Any idea why this is happening?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:39:33+00:00Added an answer on June 7, 2026 at 3:39 pm

    It doesn’t actually return a 50px difference.

    Basically the img.top is the offset from the document to the top of the image. The event.pageY is the offset of the cursor to the top of the document, as the hover event is the exact point of the cursor, not the point of the hovered object.

    If you want, you could use event.target and get the top value from that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What exactly is the scope of an HTTP session? I've been googling this but
Hello everyone :) I'm sorry for the long code listing, but I'm not sure
Exactly the below code works in a TEST project. But in my productive project
Questions exactly like this have been asked before, i've read them all and tried
What exactly is the difference? I've been using Jetty 8.0.0 lately and when I
exactly what does NUnit do when it encounters a timeout? I used to think
What exactly are the Python scoping rules? If I have some code: code1 class
I am trying to create a layout but I am not too sure how
Here I have a piece of code, I want to show the long text
Exactly as the title says. I've created an @NodeEntity annotated POJO and in it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.