amit amit - 1 year ago 94
jQuery Question

jquery draggable

i have a div i want to drag confined in a particular container.
i tried using the containment: parent option but this results in the div getting snapped to upper or lower bounds without dragging. i have overflow:hidden set, i hope that is not a problem. (i read it somewhere)

pls help me out.

the code:


$(document).ready(function() {
containment: '#imgContainer',
scroll: false

the #draggable is a div that contains the img, and #draggable is appended to imgContainer. i hope this helps somehow.

Answer Source

The following works perfectly for me (You'll have to modify the containment plots to match your draggable element dimensions though):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
<html xmlns="" xml:lang="en-us" lang="en-us">
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
      <script type="text/javascript" src=""></script>
      <script type="text/javascript" src=""></script>

    	<script type='text/javascript'>

    		  containment: [-150,-150,0,0],
    		  scroll: 'false'

    	<style type="text/css">
    	  #container {
    		border:1px solid #cccccc;
    	  #draggable {
    		background:#cc0000 url("");

      <div id="container">
    	<div id="draggable"></div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download