Git Product home page Git Product logo

jquery.pan's Introduction

Readme

jQuery.pan is a jQuery plugin that packages up commonly used mouse-based panning behaviours. Whilst being quite configurable, it aims to have sensible default options to get things up and running quickly.

Minimal Example

A minimal example is shown below. The container holds the content to be panned. The call to $('#container').pan() tells jQuery.pan to put the first child element of the container under pan control. Currently, a position of absolute or relative must be set on both the container and the content to obtain expected behaviour. Of course, the container must have at least one dimension smaller than the content in order to see panning behaviour.

<html>
    <head>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript" src="https://raw.github.com/mjfisheruk/jquery.pan/master/js/jquery.pan.js"></script>
        <style type="text/css">
            #container {
                position: relative;
                width: 250px;
                height: 250px;
                overflow: hidden;
            }            
            #content {
                position: absolute;
                width: 500px;
                height: 500px;
                background-image: url('https://raw.github.com/mjfisheruk/jquery.pan/master/img/tshirt.jpg');
            }
        </style>
    </head>
    <body>
        <div id="container">
            <div id="content"></div>
        </div>
        <script type="text/javascript">
            $('#container').pan();
        </script>
    </body>
</html>

Panning Modes

jQuery.pan currently supports three different panning modes:

  • Kinetic panning (the default). Clicking and dragging on content moves it around. If you release the mouse button whilst the cursor is still moving, content will move along with its own velocity before coming to rest - live example
  • Edge panning. Moving your cursor near to the borders of a content's container will cause the content to pan in that direction - live example
  • Proportional panning. Moving the mouse over content will cause it to immediately pan to a point based on the relative position of the cursor - live example

These can be switched by setting the mouseControl option to either 'edge', 'proportional' or 'kinetic':

$('#container').pan({
	mouseControl: 'proportional'
});

In addition, you can make content pan automatically by setting the autoSpeedX and autoSpeedY options for the horizontal and vertical axis respectively:

$('#container').pan({
	autoSpeedX: 1,
	autoSpeedY: 2
});

In this example, the content will pan back and forth along the vertical axis at twice the rate of the horizontal axis.

Options

Options relating to the kinetic panning mode:

$('#container').pan({
    'mouseControl'    : 'kinetic', //Enable kinetic panning (default)

    'kineticDamping'  : 0.8        //Lower numbers will cause the content to come to
    							   //a halt quicker. At zero, content will come to a
    							   //stop immediately after the mouse is release. At
    							   //one, content will not slow until it reaches an edge.
    							   //Numbers lower than zero or higher than one produce
    							   //undefined (but fun) behaviour.
});

Options relating to edge panning:

$('#container').pan({
    'mouseControl'    : 'edge',   //Enable edge panning

    'mouseEdgeSpeed'  : 5,        //The speed the content moves when the user
                                  //moves the mouse to the edge of the container
    
    'mouseEdgeWidth'  : 100       //The width in pixels of the mouse sensitive border
                                  //inside the container.	Defaults to a quarter of the
                                  //smallest container dimension.			
});

The proportional panning mode has no specific options.

$('#container').pan({
    'mouseControl'           : 'proportional',  //Enable proportional panning

    'proportionalSmoothing'  : 0.8              //Controls the level of smoothing on the
                                                //panning movement - takes a value between
                                                //zero and one. Values closer to one will
                                                //result in a smoother movement that will
                                                //take longer to reach its destination. A
                                                //value of zero results in an instant pan.
});

General options that effect all panning modes:

$('#container').pan({
	'autoSpeedX'      : 0,        //The speed at which the content will pan along the horizontal
	'autoSpeedY'      : 0,        //and vertical axis respectively when no user interaction
	                              //is occuring. Both options default to zero
    
    'updateInterval'  : 50        //The interval (in milliseconds) between updates. Defaults
                                  //to 50, which will yield a rough framerate of 20fps. Note
                                  //that where speeds are specified they are given in pixels
                                  //moved per update, so they are *not* currently framerate
                                  //independent
});

Flags

Flags my be added as CSS classes to the container element

  • pan-off: adding this class to the container element will disable any panning behaviour. Removing it will begin the panning again.

jquery.pan's People

Contributors

mjfisheruk avatar xpacmanx avatar mattfisherdubit avatar

Stargazers

Chia avatar Valerio Ageno avatar Liza avatar ulrike avatar evan orensky avatar Arielle Nguyen avatar  avatar

Watchers

 avatar  avatar

jquery.pan's Issues

Temporarily disabling pan

Thanks for creating this - very useful!

Is there a way to remove pan from an element temporarily?

Zooming element before pan

I'm looking to have an element zoom before proportional scrolling starts, but the way sizing is calclated before zooming means the element doesn't pan right to the edges, it's working from the smaller sizes.

I've paired jQuery.pan with Zoomooz here: https://jsfiddle.net/kevngibsn/5okxr8n3/30/

Before the zoom panning works fine, after the zoom you can see there's an issue.

Is there any way to recalculate sizing after zoom? Or a way to use only jQuery.pan to handle the zoom at the start as well as the panning?

I'm so close to getting what I need, would hate to have to start looking for another solution.

Firefox problem

Hello,

The pan is not working on firefox. Any idea how to fix it?
Thanks

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.