Actually I’m looking for a jQuery plug-in that can handle this:
- there is a container with overflow hidden
- inside of this is another one, which is way larger
- when i move over the div, the part I’m seeing depends on my current position
- when I’m in the left top corner I see the top left corner of the inner container
- when I’m in the middle i see the middle of the container …
I wrote a little JavaScript that does that:
this.zoom.mousemove( function(event) {
var parentOffset = $(this).parent().offset();
var relativeX = event.pageX - parentOffset.left;
var relativeY = event.pageY - parentOffset.top;
var differenceX = that.zoom.width() - that.pageWidth;
var differenceY = that.zoom.height() - that.pageHeight;
var percentX = relativeX / that.pageWidth;
var percentY = relativeY / that.pageHeight;
if (1 < percentX) {
percentX = 1;
}
if (1 < percentY) {
percentY = 1;
}
var left = percentX * differenceX;
var top = percentY * differenceY;
that.zoom.css('left', -left).css('top', -top);
});
But this isn’t very smooth and kinda jumpy, when you enter from another point of the container. So, before reinventing the wheel: Is there one plug in, that does exactly that and has iOS support (drag instead of mouse move)? All zoom plug ins (like Cloud Zoom) are over the top for this purpose and most have no support for dragging on iOS.
And if there’s not something like this. How can I make this smoother and cooler. Any approach would be helpful. 🙂
Many thanks.
So, here is my solution – which works pretty well and is easy to achieve. There could be done some improvement, but to get the idea i’ll leave it that way. 🙂
there is a demo on jsfiddle:
http://jsfiddle.net/insertusernamehere/78TJc/
CSS
HTML
JAVASCRPT
Note:
This one has, of course, no support for touch devices. But for that I use (again)/I can recommend the good old iScroll … 🙂