<link rel="stylesheet" href="http://dl.dropbox.com/u/107346/share/ui-lightness/jquery-ui.css">
<div id="viewport">
<!-- "crosshairs" is just here to visually reference the center point for this example -->
<img id="crosshairs" src="http://dl.dropbox.com/u/107346/share/crosshairs.png" alt="" />
<img id="map" src="http://dl.dropbox.com/u/107346/share/fake-map.png" alt="" />
</div>
<div id="zoom-control"></div>
<p>↑ zoom</p>
<p id="debug"></p>
function trace(message) {
$('#debug').html(message);
}
var map = $('#map');
var viewport = $('#viewport');
map.draggable();
$('#zoom-control').slider({
min: 300,
max: 1020,
value: 300,
step: 24,
create: function() {
map.css({
'width': 300,
'left': 0,
'top': 0
});
},
slide: function(event, ui) {
var old_width = map.width();
var new_width = ui.value;
var width_change = new_width - old_width;
var css_properties = {
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)
};
map.css(css_properties);
trace((map.position().left));
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.