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 7524057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:58:51+00:00 2026-05-30T02:58:51+00:00

I met some basic problem in jquery, but I can’t figure it out. Here

  • 0

I met some basic problem in jquery, but I can’t figure it out.

Here is the code: http://jsfiddle.net/pdQsY/

How do I get the position of half of a div.(mouseover left 200px of the div, output font color #ff0. mouseover right 200px of the div, output font color #336)

I use e.pageX - div.offsetLeft, but this echo NaN, thanks.

  • 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-05-30T02:58:52+00:00Added an answer on May 30, 2026 at 2:58 am

    Use .offset().left instead of the non-existent jQuery property offsetLeft.

    For efficiency considerations, you should cache the $("#main") and $('p') variable. You’re calling this twice in your mousemove handler. The mousemove handler is fired very often, so you end up calling $("#main") over thousand times, easily.

    Demo: http://jsfiddle.net/pdQsY/2/

    var $main  = $("#main");
    var $p = $('p');
    $main.mousemove(function(e) {
        var mouseX = e.pageX;
        var offsetLeft = $main.offset().left;
        if(mouseX < 200 + offsetLeft){
             $p.css('color','#ff0');
        } else {
             $p.css('color','#336');
        }
        $p.html(mouseX - offsetLeft);
        e.preventDefault();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I follow the demo http://jquery.bassistance.de/validate/demo/marketo/ and met some problems to achieve the same remote
I met some compilation error but do not know what the problem is. The
I want to make a PHP JSON data foreach, but I met some problem.
So, here is some basic code which illustrates my question: #include <functional> int func(int
In some project i met this code: erb = yield.src I can't understand what
While i making some kind of jQuery image rotator, i met problem. Where is
I have an implementation that just like gmail application, but have met some problem
guys I know this question is very basic but I've met in few publications
I have some JavaScript/jQuery code that watches for the changed event on a checkbox:
I developed some WPF projects, but I met a very serious issue. As you

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.