Code Monkey home page Code Monkey logo

smartjqueryzoom's Introduction

#Zoom and pan jQuery plugin

This plugin manage smooth zoom and pan on a given dom element. The plugin works on mobile and pc and use CSS3 transitions on compatible web browsers. (javascript is used for old web browsers)

Zoom is enabled via mouse events (scroll and click) on pc and with touch events on mobile devices.

For live examples and more explanations visit : http://e-smartdev.com/#!jsPluginList/panAndZoomJQuery

##Initialization

  $(document).ready(function() {
    $("#elementToZoomOn").smartZoom(); // start plugin behaviour
  });

##Options You can customize smartZoom plugin behaviour with an option object.

options = {'top' : '0', // zoom target container top position in pixel
           'left' : '0', // zoom target container left position in pixel
           'width' : '100%', // zoom target container width in pixel or in percent
           'height' : '100%', // zoom target container height in pixel or in percent 
           'easing' : 'smartZoomEasing', // jquery easing function used when the browser doesn't support css transitions
           'maxScale' : 3, // the max scale that will be applied on the zoom target
           'dblClickMaxScale' : 1.8, // the max scale that will be applied on the zoom target on double click
           'mouseEnabled' : true, // enable plugin mouse interaction 
           'scrollEnabled' : true, // enable plugin mouse wheel behviour
           'dblClickEnabled' : true, // enable plugin mouse doubleClick behviour
           'mouseMoveEnabled' : true, // enable plugin target drag behviour
           'moveCursorEnabled' : true, // show moveCursor for drag
           'touchEnabled' : true, // enable plugin touch interaction 
           'dblTapEnabled' : true, // enable plugin double tap behaviour 
           'pinchEnabled' : true, // enable zoom when user pinch on target
           'touchMoveEnabled' : true, // enable target move via touch
           'containerBackground' : '#FFFFFF', // zoom target container background color (if containerClass is not set)
           'containerClass' : ''// class to apply to zoom target container if you whant to change background or borders (don't change size or position via css)
          } 

This sample code set the maximum scale to 4 and apply a red background to the zoom container:

  $(document).ready(function() {
    $("#elementToZoomOn").smartZoom({'maxScale':4, 'containerBackground':'#FF0000'}); // start plugin behaviour
  });

##Methods

###smartZoom("zoom", scaleToAdd, globalRequestedPosition, duration) Zoom on a given position.

	jQuery(document).ready(function(){
	     $('#domElementToZoom').smartZoom("zoom", 0.5);
	});

This call add 0.5 to the target current scale.

Arguments

  1. scaleToAdd {Number}: Scale to add to the target.
  2. globalRequestedPosition {Object}: Position to zoom on. (Default target center)
  3. duration {Number}: Effect duration in millisecondes. (Default 700)

###smartZoom("pan", pixelsToMoveOnX, pixelsToMoveOnY, duration) Move the target on the given position.

	jQuery(document).ready(function(){
     $('#domElementToZoom').smartZoom("pan", 5, 0);
  });

This call move the target 5 pixels to the right.

Arguments

  1. pixelsToMoveOnX {Number}: Pixels to add on horizontal axis
  2. pixelsToMoveOnY {Object}: Pixels to add on vertical axis.
  3. duration {Number}: Effect duration in millisecondes. (Default 700)

###smartZoom("destroy") Remove and clean the plugin.

	jQuery(document).ready(function(){
      $('#domElementToZoom').smartZoom("destroy");
  });

Remove the plugin behaviour.

###smartZoom("isPluginActive"):Boolean Check if the plugin is active or not.

	jQuery(document).ready(function(){
     if($('#zoomImage').smartZoom('isPluginActive'))
          $('#zoomImage').smartZoom('destroy'); 
     else
          $('#zoomImage').smartZoom();
  });

If the plugin is activate, remove it else launch it.

smartjqueryzoom's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smartjqueryzoom's Issues

Poor Quality in safari, webkit

Thank you for smartJQueryZoom!
Results in Firefox are perfect, but Safari gives poor, blurry zooms.
We divide our large image into 6 tiles and scale them down to 1/4 size.

div id="imageFullScreen"
div id="allimageparts"
img src="images/zoom1.jpg" width="400" height="400" alt="." /
img src="images/zoom2.jpg" width="400" height="400" alt="." /
img src="images/zoom3.jpg" width="400" height="400" alt="." /
img src="images/zoom4.jpg" width="400" height="400" alt="." /
img src="images/zoom5.jpg" width="400" height="400" alt="." /
img src="images/zoom6.jpg" width="400" height="400" alt="." /
/div
/div

Our tiles are all 1600px x 1600px

We scale up to 'maxScale':4 and the result is perfect in Firefox, but ugly blurry in Safari, Webkit.

Any idea or hints would be great.

Thank you,
elEglon

Collision with draggable items

Hello,

I am using this library along with dragabble/droppable from jQuery. After using the zoom plugin, the draggable becomes unusable. I think it is because of this line:

document.ondragstart = function () { return false; }; // allow to remove browser default drag behaviour

The destroy method does not re-set the document.ondragstart to it's original value. Is this intended?

IE < 10 : Content not scaled to Container

When "css3dSupported" is false in line 781 no object will be generated and the return value of "getBrowserTransitionObject" wille subsequently be "null". This is the case in every browser that does not support "translate3d", in this here case IE9.

Since the object is "null" in line 652 "if (smartData.transitionObject != null)" will evaluate to false, thus the else case in lines 660/661 will never be executed as it will only be executed when "smartData.transitionObject != null" and "smartData.transitionObject.css3dSupported == false", an unreachable state as the first prevents the later.

Based on this "translateX" in line 661 will never be executed -> Content not scaled to Container in IE9.

I hope this helps fixing the issue,
thank you in advance.

combination of two plugins

Hi all,
I try to embed the realy smart smartJQueryZoom into a swiper-Structure (using https://github.com/nolimits4web/Swiper). On swiped layers the zoom runs to the bottom of my page, only on the first slide it works as desired. :(
Thank you for any help concerning the control of the containers position.
Eglon

Snippet

.
.
.

how to get image coordinates while panning/zooming

First of all, thank you for creating such an awesome tool with mobile support.

I am actually trying to get the coordinates of an image (x1, y1, x2, y2, width, height) either it is in static position or during zoom and pan. I tried to figure out your code but I did not find any place or piece of code which could help me to get this info.

I will appreciate your help if you could help me to find out the require info plus if you add a default functionality for getting the coordinates of an image (like this plugin http://benlumley.co.uk/dev/panzoom/example/index.html) than it would be another great addition in the plugin.

smartzoom plugin is growing the containing div

I'm using the smartzoom jquery plugin, and it seems to work fine on my jsfiddle using jQuery 1.8.3, but if I use jQuery 1.9.1 (and include the Migrate 1.1 plugin for compatibility), I get some strange behaviour.

What happens is when I resize the bottom-right frame in the jsFiddle, the div that smartzoom creates grows in size, even if I reduce the size of the frame back. Any alteration in the frame's size causes the div to grow, resulting in the image drifting further down the page.

Here's my jsFiddle to demonstrate this: http://jsfiddle.net/76wgC/4/

Events for custom smartzoom-element children get lost

Events which are bound to child-elements of my smartzoom-element get lost after initialisation.
This is caused by the call of jQuery.remove() in line 94. It removes all assosiated data and events from the element and all the children.

So to improve the library for compatibility with other use cases it is recommended to use jQuery.detach() instead to keep all assosiated events and data after removing from DOM and appending in line 99.

touch pan/zoom on Android waits until touchend before displaying change.

I only have android devices to test this,
but in your demo example, when its in fullscreen it works ok ( a bit glitchy to get started, but otherwise basically working)
however, when I try to simply zoom or pan the image when its not fullscreen,
no visible change occurs until touch end. occurs for both zoom and pan.

Initialisation uncertainty

Hi,
I'm trying to do something like this:
$targetEl.smartZoom({'containerClass':'cropFrame'});
var containerDiv= $targetEl.data('smartZoomData').containerDiv;
...
I want a reference to the containerDiv so that I can attach controls and event handlers to it.
Unfortunately because I also pass an initialiser object to smartZoom and my target is an image, it does not initialize immediately, but delegates to an event handler. this means that the .data object isn't always initialised yet when the .smartZoom call returns.

Do you have any advice as to how I might best work around this?
thanks

The plugin seems to not work on all resolutions?

I need to have a bottom bar in my website, the problem is the image takes up the entire screen. If I set 'height' : '70%' then what happens is it works good on my desktop res but as soon as I try out smaller window sizes like a mobile device, the image either takes up entire screen or somehow cuts in half? How can I solve this problem so its perfect on all resolutions?

How to optimize it for HTML content panning?

Hi all,

smartJQueryZoom works smooth with images, but it's extremely slow on mobile with HTML content. There's a 200-300 msec delay between finger move and the content move. Zoom is smooth, but panning is not.

Any ideas hot make in smoother?

smartZoom("destroy") doesnt remove extra style data

I start out with an image target looking like this:

<img id="blah" src="some.jpg" alt="your image" >

after intializing smartZoom, and then
after calling smartZoom("destroy") my image is left looking like this:

<img id="blah" src="some.jpg" alt="your image" style="transition: all 0.005s ease-out; 
-webkit-transition: all 0.005s ease-out; 
-webkit-transform: translate3d(0px, -1290px, 0px) scale3d(1, 1, 1); 
cursor: default; -webkit-transform-origin: 0px 0px; visibility: visible;">

so the image is neither restored, nor is it left looking like it was after pan/zoom.
instead its height is severely culled and the whole image shrinks to the top of my page.

Add "panto" function to allow direct position assignment

I'd rather specify the new position than add or remove pixels from the pan position, which doesn't seem possible to me, so I created the following function to enable this feature.
Feel free to edit and/or integrate.

    /**
      * panto function accessible via direct call (ex : $('#zoomImage').smartZoom('panto', 5, 0);)
      * @param {Number} xPos : a number to move the object current position in X
      * @param {Point} yToAdd : a number to move the object current position in Y
      * @param {Number} duration : move effect duration 700ms by default
      */
    panto : function(xPos, yPos, duration){
        if(xPos == null || yPos == null) // check params
            return;

        if(duration == null) // default pan duration is 700ms
            duration = 700;

        var currentPosition = targetElement.offset();

        var targetRect = getTargetRect();
        var validPosition = getValidTargetElementPosition(xPos, yPos, targetRect.width, targetRect.height); // add the given numbers to the current coordinates and valid the result

        if(validPosition.x != currentPosition.left || validPosition.y != currentPosition.top){
            // stop previous effect before make calculation
            stopAnim(ESmartZoomEvent.PAN);
            moveOnMotion(xPos, yPos, duration);
        }
    },

CSS Error - transform. declaration missing

Firefox 34.
On demo work fine. But on my site build with bootstrap 2 not work, no js error or warning. But in css warning is "error on parse value for 'transform'. Missing declaration'

What is wrong ?
Thx

zoom out is too much

when i am implementing plugin for zoom ,by default the zoom out is too much which makes it to small to view.

how to resolve it.

I am using below code :

        $(document).ready(function() {

            $('#canvas').smartZoom({'containerClass':'zoomableContainer'});

            $('#topPositionMap,#leftPositionMap,#rightPositionMap,#bottomPositionMap').bind("click", moveButtonClickHandler);
            $('#zoomInButton,#zoomOutButton').bind("click", zoomButtonClickHandler);

            function zoomButtonClickHandler(e){
                var scaleToAdd = 20;

                if(e.target.id == 'zoomOutButton')
                    scaleToAdd = -scaleToAdd;
                $('#canvas').smartZoom('zoom', scaleToAdd);
            }

            function moveButtonClickHandler(e){
                var pixelsToMoveOnX = 0;
                var pixelsToMoveOnY = 0;

                switch(e.target.id){
                    case "leftPositionMap":
                        pixelsToMoveOnX = 100;  
                    break;
                    case "rightPositionMap":
                        pixelsToMoveOnX = -50;
                    break;
                    case "topPositionMap":
                        pixelsToMoveOnY = 50;   
                    break;
                    case "bottomPositionMap":
                        pixelsToMoveOnY = -50;  
                    break;
                }
                $('#canvas').smartZoom('pan', pixelsToMoveOnX, pixelsToMoveOnY);
            }

        });

Fit or Fill the image for images smaller than the container

Hi there,
I'm trying to use this plugin with images that are smaller than the target container. (avatars in a container big enough to manipulate)
I'd like to scale up the images so that they are properly adjusted to fit/fill by the smallest dimension, and are never able to shrink smaller than the container.
the adjustToContainer method, only seems to cater to the case where the image is larger, otherwise it always calculates a scale of 1, where a scale of >1 is what I want to lock in as a minimum (I think).
what's the best way to 'fill' an image into the container so that the image always consumes the entire container, and cannot ever be dragged/zoomed to show background?

Cheers

without body { margin:0; } pan doesn't work

Hi, thanks for the nice plugin,
I have been tinkering with it in chrome & firefox, but could not fathom why it would not work in my own html. eventually I narrowed it to this:
in your own example, if you leave out the css then panning wont work (in chrome & ff at least).
restoring this single entry allows panning to work again:
html, body {margin:0;}

in fact setting the margin to anything but zero doesn't work either, nor does it have any effect unless its on the body element.

I hope either this dependency gets fixed, or at least this comment helps someone else out.

Cheers

Image is not truly full screen in full screen mode.

Some of my images load with small top/bottom or side margins. You can see this behavior in your own full screen example. Depending on the browser's window size sometimes you don’t see this issue right away. If that’s the case then try resizing the window slowly and you will see these margins appear/disappear depending on the window's size. If you stop resizing just at the right time you may see margins on all four sides. Is there a way to get rid of them? Thank you.

Two different objects

Can you assign a .smartZoom(); to two different objects with two different options?

does't work with iframe?

On iPhone device When load html with iframe it seems not initiate correctly. The BIG image in the html does not resized. And the same code works fine not using iframe. Also both are satisfied on PC.
And there is another problem, jQuery not support PASSIVE option when add event listener, so in some circumstances e.preventDefault will not works.cause the page can not drag.

Marker support..?

Hello,

First of all this is an awesome plugin. The mobile support is great! I was wondering if it would be possible to add markers to the container so that they would be stationary on top of the image, like the markers in Google Maps.

Just curious! Thanks :)

Transform-origin IE11

Hi,

Love you script BTW.

EDIT: I'm not sure the problem resides in what I explain but I guess it's something like that sinze HTML2CANVAS render the image based on the css.

I'm using this with HTML2CANVAS i'm having an issue related to the transform-origin. When html2canvas render the page he recognize the transform-origin wich is always 0 0 wich make the image to be in the wrong position.

I´ve tried to manipulate the script but somehow if I remove that property he doesnt work. Aswell if I try to manipulate it by change the left top dynamicly he also doenst work properly( The PanAndZoom itself ).. Is there anyway to use the script without this property since it's always 0 0 ?

Many thanks.

Zoom with images slider

Hi,
I have used the e-smartdev zoom library with swiper master slider.
zoom and slider work fine. But sometimes it doesn't show the UI elements on the gallery when I check this with an Android tablet. (zoom is working)
Like pagination, arrow navigation. And I have used some my own buttons to interact. All are disappearing with zoom image load. What is the problem with it.
Please help me...
The slider I have used
https://github.com/nolimits4web/Swiper

Thanks alot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.