Giter VIP home page Giter VIP logo

jquery-draggable-background's Introduction

Draggable Background

A jQuery plugin to make background images draggable.

NOTE: I don't plan to maintain this library anymore since I've moved on from jQuery. There seems to be requests for supporting different options for background-size or different units for background-position. After looking at the css spec for these properties, it seems unmaintainable to support every possible configuration, so I would encourage you to fork this and shape it to your specific needs.

Configuration

Option Type Known Values Default Value Description
bound Boolean true|false true Whether dragging is bounded by the edges of the image.
axis String x|y If specified, restrict dragging along x or y axis.
done Function Called when dragging is stopped by mouseup, touchup, or mouseleave.

Usage

// default options
$('div').backgroundDraggable();

// only draggable in the x direction, and dragging is not bounded by the image
$('div').backgroundDraggable({ bound: false, axis: 'x' });

// disable draggable background
$('div').backgroundDraggable('disable');

// callback when drag complete
$('div').backgroundDraggable({
  done: function() {
    backgroundPosition = $('div').css('background-position');
    console.log(backgroundPosition);
  }
});

Demo

http://kentor.github.com/jquery-draggable-background/

Support

IE9+. Only background-size value of auto (default) and cover are supported. background-position must be absolute pixels. There will be bugs if you use center for percentages.

Changelog

v1.2.3 [2014-10-17]

  • Fixed child elements of element with background dragging calling preventDefault (7f17318).
  • Improved behavior of dragging, especially when mouse up happens outside the window (d1fdbe4).

v1.2.2 [2014-09-01]

  • Added support for a callback when dragging is finished.

v1.2.1 [2014-08-01]

  • Added support for disabling plugin

v1.2 [2014-06-06]

  • Refactored code to use semicolons.
  • Support for background-size: cover.

v1.1 [2013-05-19]

  • Touch support.

v1.0 [2012-09-23]

  • Initial release.

License

Copyright (c) 2014 Kenneth Chung

Licensed under the MIT license.

jquery-draggable-background's People

Contributors

enumag avatar jeffsaracco avatar kentor avatar robertabramski avatar

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jquery-draggable-background's Issues

A question

Hi,

is it possible to add features like resizable, crop, and rotatable to the already cool draggable? :) Sorry this is just a question, not an issue.

Callback function at the end

Hi,

Great plugin!

Would be nice to have a callback function at the end to know if the background is in the final position. Do you plan to do sy like this?

First click to 0,0

I'm sure I'm missing something here but where can I stop it resetting to 0,0 when I first click on the background?

Also it's made my forms unresponsive, I cannot enter anything in them.

http://www.enzly.co.uk/tonity/

any suggestions? :)

Toggle on/off?

How would I remove the plugin after initializing it? Or turn toggle it on/off?

Conflicts With Draggable/jQuery UI

Is it possible for this to co-exist with Draggable? Currently if I have a "draggable" div over a div with backgroundDraggable, the background gets dragged when the draggable div gets dragged.

Endless dragging

Hi, I have a little problem.

on my website I use your script.

When dragging right or down, the background stops when I reaches the end of the picture.
However, if dragging to the left or up, you can drag it forever and all you get is the background color behind the picture (default white of course).

in your demo this doesn't happen.

do you have any idea what could be the problem?

Small bug found (typo)

The typo is found at line 118, $window.one('mouseup.dbg touchend.dbg mouseleave.dbg', function() { should be changed to $window.on('mouseup.dbg touchend.dbg mouseleave.dbg', function() {.

P.S. Notice the one instead of on.

Typo was commited d1fdbe4

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.