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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:05:55+00:00 2026-05-19T09:05:55+00:00

I’m new to jquery and javascript, and to web site developing overall, and I’m

  • 0

I’m new to jquery and javascript, and to web site developing overall, and I’m having a problem with the .offset function. I have the following code working fine on chrome and FF but not working on IE:

$(document).keydown(function(k){  
    var keycode=k.which;  
    var posk=$('html').offset();  
    var centeryk=screen.availHeight*0.4;  
    var centerxk=screen.availWidth*0.4;  
    $("span").text(k.which+","+posk.top+","+posk.left);  
    if (keycode==37){  
        k.preventDefault();  
        $("html,body").stop().animate({scrollLeft:-1*posk.left-centerxk})  
    };  
    if (keycode==38){  
        k.preventDefault();  
        $("html,body").stop().animate({scrollTop:-1*posk.top-centeryk})  
    };  
    if (keycode==39){  
        k.preventDefault();  
        $("html,body").stop().animate({scrollLeft:-1*posk.left+centerxk})   
    };
    if (keycode==40){
        k.preventDefault();
        $("html,body").stop().animate({scrollTop:-1*posk.top+centeryk})
    };  
});  

hat I want it to do is to scroll the window a set percentage using the arrow keys, so my thought was to find the current coordinates of the top left corner of the document and add a percentage relative to the user screen to it and animate the scroll so that the content don’t jump and the user looses focus from where he was. The $(“span”).text are just so I know what’s happening and will be turned into comments when the code is complete.

So here is what happens, on Chrome and Firefox the output of the $(“span”).text for the position variables is correct, starting at 0,0 and always showing how much of the content was scrolled in coordinates, but on IE it starts on -2,-2 and never gets out of it, even if I manually scroll the window until the end of it and try using the right arrow key it will still return the initial value of -2,-2 and scroll back to the beggining.

I tried substituting the offset for document.body.scrollLetf and scrollTop but the result is the same, only this time the coordinates are 0,0. Am I doing something wrong? Or is this some IE bug? Is there a way around it or some other function I can use and achieve the same results?

On another note, I did other two navigating options for the user in this section of the site, one is to click and drag anywhere on the screen to move it:

$("html").mousedown(function(e)
{
    var initx=e.pageX
    var inity=e.pageY
    $(document).mousemove(function(n)
    {   
        var x_inc= initx-n.pageX;
        var y_inc= inity-n.pageY;
        window.scrollBy(x_inc*0.7,y_inc*0.7);
        initx=n.pageX;
        inity=n.pageY
        //$("span").text(initx+ "," +inity+ "," +x_inc+ "," +y_inc+ "," +e.pageX+ "," +e.pageY+ "," +n.pageX+ "," +n.pageY);

    // cancel out any text selections
    document.body.focus();

    // prevent text selection in IE
    document.onselectstart = function () { return false; };
    // prevent IE from trying to drag an image
    document.ondragstart = function() { return false; };

    // prevent text selection (except IE)
    return false;
    });
});

$("html").mouseup(function()
{
    $(document).unbind('mousemove');
});

The only part of this code I didn’t write was the preventing text selection lines, these ones I found in a tutorial about clicking and draging objects, anyway, this code works fine on Chrome, FireFox and IE, though on Firefox and IE it’s more often to happen some moviment glitches while you drag, sometimes it seems the “scrolling” is a litlle jagged, it’s only a visual thing and not that much significant but if there’s a way to prevent it I would like to know.

  • 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-19T09:05:56+00:00Added an answer on May 19, 2026 at 9:05 am

    okay I just solved my problem changing the posk variable to

        var poskt=$(document).scrollTop(); 
    

    and adding an new var for scrollLeft, this way the code behave the same on Chrome, FF and Internet Explorer

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.