SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery draggable / droppable

    I've been trying to implement some simple draggable / droppable code (below) with no success. The items drag, revert and stay in containment. However, when dropped in the droppable area the item gives the alert, as it should, but it is then no longer draggable.

    Ideally, I would like to have the item draggable between the drag and drop areas. Just in case the user moves it to the droppable area and then changes their mind. Once in the droppable area, I would like to also allow the item to be movable in there.

    Am I overlooking something obvious? Everything I found searching looked like it was pretty basic and straightforward to implement.

    Code CSS:
    div.build_board_text
    {
    	position: absolute;
    	top: 500px;
    	width: 1100px;
    	height: 900px;
    	color: #747070;
    	font-family: Trebuchet MS;
    	font-size: 12px;
    	line-height: 17px;
    }
    body.print-vision-boards .build_board_text
    {
    	width: 1100px;
    	height: 1700px;
    	top: 267px;
    }
    .draggable_item
    {
    	width: 90px;
    	height: 90px;
    	padding: 0.5em;
    	float: left;
    	margin: 0 10px 10px 0;
    	cursor: move;
    }
    #src_landscape_8-5x11
    {
    	display: block;
    	border: 1px solid #000;
    	float: left;
    	width: 382px;
    	min-height: 295px;
    	height: auto !important;
    	height: 295px;
    	padding: 0px;
    	position: relative;
    	margin: 0px auto 40px auto;
    	list-style: none;
    }
    Code HTML4Strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Test</title>
    <script type="text/javascript" src="/jquery-1.5.1.min.js"></script>
    <!--<script type="text/javascript" src="/jquery-ui-1.8.11.custom.min.js"></script>-->
    <script type="text/javascript" src="/jquery.ui.core.min.js"></script>
    <script type="text/javascript" src="/jquery.ui.widget.min.js"></script>
    <script type="text/javascript" src="/jquery.ui.mouse.min.js"></script>
    <script type="text/javascript" src="/jquery.ui.draggable.min.js"></script>
    <script type="text/javascript" src="/jquery.ui.droppable.min.js"></script>
    <script type="text/javascript" src="/jquery.ui.position.min.js"></script>
    <script type="text/javascript">
    $(document).ready
    (
    function()
    {
    	$('.draggable_item').draggable
    	({
    		revert: true,
    		containment: '#build_board_text'
    	});
     
    	$('#dst_landscape_8-5x11').droppable
    	({
    		drop: function(event, ui)
    		{
    			alert('Dropped!');
    		}
    	});
    });
    </script>
    </head>
    <body>
        <div class="build_board_text" id="build_board_text">
     
    <div id="src_landscape_8-5x11">
     
    			<div id="draggable_1" class="draggable_item">
    				<img src="../ImageLibrary/image1.jpg" width="70" height="70" alt="" /><br />Text 1.
    			</div>
    			<div id="draggable_2" class="draggable_item">
    				<img src="../ImageLibrary/image2.jpg" width="70" height="70" alt="" /><br />Text 2.
    			</div>
    		</div><!-- source list -->
    		<div id="dst_landscape_8-5x11">&nbsp;</div><!-- destination list -->
     
        </div><!-- build_board_text -->
     
    </body>
    </html>

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been searching and trying a few things, but haven't had any luck - see link below. Any insight?

    jsfiddle.net/ySa3h/2/

  3. #3
    SitePoint Addict
    Join Date
    Jul 2008
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For anyone's future reference.

    Turns out that the issue, for whatever reason, is with the positive: relative CSS in the #dst_landscape_8-5x11 style. Removed that and it worked.

    I also had to change the 2nd droppable accept: to #src_landscape_8-5x11 div rather than #dst_landscape_8-5x11 div


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •