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

  • Home
  • SEARCH
  • 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 7015961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:43:16+00:00 2026-05-27T22:43:16+00:00

This seems like it should be quite simple, but for some reason I can’t

  • 0

This seems like it should be quite simple, but for some reason I can’t quite wrap my brain around it. I have an image inside a “viewport” div, of which the overflow property is set to hidden.

I’ve implemented a simple zooming and panning with jQuery UI, however I am having trouble getting the zoom to appear to originate from the center of the viewport. I did a little screencast from Photoshop the effect I’m trying to reproduce: http://dl.dropbox.com/u/107346/share/reference-point-zoom.mov

In PS you can adjust the scaling reference point an the object will scale from that point. Obviously this is not possible with HTML/CSS/JS, so I’m trying to find the appropriate left and top CSS values to mimic the effect.

Here is the code in question, with a few unnecessary bits removed:

html

<div id="viewport">
    <img id="map" src="http://dl.dropbox.com/u/107346/share/fake-map.png" alt="" />
</div>

<div id="zoom-control"></div>

javascript

$('#zoom-control').slider({
    min: 300,
    max: 1020,
    value: 300,
    step: 24,
    slide: function(event, ui) {
        var old_width = $('#map').width();
        var new_width = ui.value;
        var width_change = new_width - old_width;
        $('#map').css({
            width: new_width,

            // this is where I'm stuck...
            // dividing by 2 makes the map zoom
            // from the center, but if I've panned
            // the map to a different location I'd
            // like that reference point to change.
            // So instead of zooming relative to
            // the map image center point, it would
            // appear to zoom relative to the center
            // of the viewport. 
            left: "-=" + (width_change / 2),
            top: "-=" + (width_change / 2)
        });
    }
});

Here is the project on JSFiddle: http://jsfiddle.net/christiannaths/W4seR/

  • 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-27T22:43:17+00:00Added an answer on May 27, 2026 at 10:43 pm

    I have always relied on the kindness of strangers. Pertinent changes:

    // Calculate the offset as a percentage, accounting for the height of the window
    var x_offset = ((map.position().left-150))/(old_width/2);
    var y_offset = ((map.position().top-150))/(old_width/2);
    
    var css_properties = {
        width: new_width,
        // Set the offset based on the existing percentage rather than 1/2
        // then readjust for the height of the window
        left: (new_width * x_offset /2 ) + 150 + "px", 
        top: (new_width * y_offset /2 ) + 150 + "px"
    };
    

    Replace the hardcoded 150 with a variable set on viewport instantiation if necessary.

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

Sidebar

Related Questions

This seems like it should be obvious but I can't figure it out. Suppose
This seems like it should be really simple, but I'm unable to figure this
This seems like it should be something very easy to do, but every time
This seems like it should be an easy thing to do, but for the
This seems like it should be pretty straight forward, but I'm apparently confused. I
It seems like this should be straightforward but I'm boggling. I've got my listview
This seems like it should be something I already know. We need to run
This seems like it should be very easy...anyway, it is in MS SQL Server
Hi this seems like it should work, from something in collectionofsomestuff select new SelectListItem(){Text
It seems like this should be something built into jQuery without the need for

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.