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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:02:19+00:00 2026-06-07T08:02:19+00:00

I have a page with the following functionality: there is a large image that

  • 0

I have a page with the following functionality: there is a large image that generates scoll (both horizontally and vertically) and a button in a fixed position (it remains in the top left corner, even with scroll) that, when clicked, fits the image to the client width.

Since position: fixed is not supported in Internet Explorer 8, I used a workaround – this is the function:

function setFixedPosition(jqueryWrapper, pixelsFromTop, pixelsFromLeft) {

    jqueryWrapper.css('position', 'absolute');

    var setOffsets = function() {
        jqueryWrapper.css("top", (($(window).scrollTop() + pixelsFromTop) + "px"));
        jqueryWrapper.css("left", (($(window).scrollLeft() + pixelsFromLeft) + "px"));
    };

    setOffsets();

    $(window).scroll(function() {
        setOffsets();
    });
}

setFixedPosition($('#zoomFitButton'), 15, 15);

This is the button’s action:

$('#zoomFitButton').click(function() {
    $('img.preview').css('width', '100%');
});

The button remains fixed both in Firefox 13 and IE8.

But, under IE8, if I am scrolling somewhere, then I click the button, the button moves to a “strange” position:

  • If I scroll vertically, then click, it puts the button in the lower-left corner;
  • If I scroll horizontally, then click, it puts the button in the upper-right corner;
  • If I scroll both ways, then click, it puts the button somewhere in the center.

In Firefox, the button always remains in the upper-left corner (the place where I expect it to be), even after I click the fit to width button.

Here is a test page.

Is my code OK for this functionality (in principle), or I need to add something to the fit to width action (to fix my button positioning); or there is something wrong with IE (and I need a workaround – if so, any suggestions?)?

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-06-07T08:02:20+00:00Added an answer on June 7, 2026 at 8:02 am

    I found a solution that works in IE6 also.

    I think the problem has something to do with IE not updating the scrollTop and scrollLeft positions after the document is resized.

    So, after I resize the picture, I have to scroll to the upper-left corner (scrollTop(0) and scrollLeft(0)).

    Unfortunately, if I have a large picture that needs vertical scrolling even when it’s fit to width, the workaround brings me to the top of the page. So I added code to bring me back proportionally to the aproximate position I was before. I wrapped the logic in a more generic function:

    function doSomethingThatAffectsScrollPosition(affectingScrollPositionFunction) {
    
        var oldDocumentWidth = $(document).width();
        var oldScrollFromLeft = $(window).scrollLeft();
    
        var oldDocumentHeight = $(document).height();
        var oldScrollFromTop = $(window).scrollTop();
    
        affectingScrollPositionFunction();
    
        var newDocumentWidth = $(document).width();
        var widthRatio = (newDocumentWidth / oldDocumentWidth);
        var newScrollFromLeft = (oldScrollFromLeft * widthRatio);
    
        var newDocumentHeight = $(document).height();
        var heightRatio = (newDocumentHeight / oldDocumentHeight);
        var newScrollFromTop = (oldScrollFromTop * heightRatio);
    
        $(window).scrollLeft(0); // Needed for button repositioning
        $(window).scrollLeft(newScrollFromLeft);
    
        $(window).scrollTop(0); // Needed for button repositioning
        $(window).scrollTop(newScrollFromTop);
    }
    

    And I used the function in the fit to width button’s action:

    $('#zoomFitButton').click(function() {
        doSomethingThatAffectsScrollPosition(function() {
            $('img.preview').css('width', '100%');
        });
    });
    

    Here is a test page.

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

Sidebar

Related Questions

I have the following page with a black canvas inside of it: There, the
On the following page I have a link and an image, the image is
I have created an Html 5 page that provides important server-side functionality. Unfortunately, it
I have the following page structure: <span>content01</span> <span>content02</span> <span>content03</span> <br/> <span>content04</span> <span>content05</span> <span>content06</span> <br/>
I have a page with the following two divs: <div id=searchResults> </div> <div class=postSearchOptions
What is the best method of doing the following: I have Page A with
I have a registration page with the following code below: in the views: def
I have a search page with the following scenarios listed below. I was told
I have an html page with the following content: [...] <tr><td class=n><a href=play-1.0.1.zip>play-1.0.1.zip</a></td></tr> <tr><td
I have the following HTML page and the background color for the content is

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.