Guidelines for implementing drag and drop functionality for my specific scenario

Looking to create a restricted area for dragging elements within my app. Specifically, I want the element to only be draggable within a certain defined space.

Here is what I currently have:

http://jsfiddle.net/L73T5/10/

html

<div id='background'>

</div>


<div id="wrapper">
    <img id='viewer' src='http://i60.tinypic.com/1191gxt.jpg' />
</div>

css

#background{
    background: url('http://www.iiacanadanationalconference.com/wp-content/uploads/2013/01/test.jpg') no-repeat center center fixed;
    width: 100%;
    height: 100%;
    position:fixed;
    -webkit-background-size: contain;
    -moz-background-size: contain;
    -o-background-size: contain;
    background-size: contain;
    z-index: -1;
}

#wrapper{
    width: 80%;
    height: 80%;
}

#viewer{      
    cursor: pointer;
}

js

$( "#viewer" ).draggable({containment: "#wrapper", opacity: 0.65 });

I am aiming to limit the movement of the highlights image within the confines of the test image area (avoiding drag to the white background) while ensuring it remains responsive.

Can this be achieved? Thank you!

Answer №1

If you're having trouble with overlapping elements, here is a potential solution for you to try.

Check out this Fiddle Demo

In order to prevent overlap, make sure to set a specific height for your #wrapper element and adjust the positioning of the #background accordingly. Removing the fixed attribute from the background style may also help with resizing correctly.

Here's an example of how you can update your CSS:

#background{
   // any existing styles

   background: url('http://...') no-repeat top center;
   top: 50px;
}

#wrapper{
 width: 100%;
 height: 45px;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Resolving the Issue of jQuery Displaying NaN Value

I've got the code below, and it's all working smoothly. However, I'm encountering an issue where jQuery is returning $NaN when I try to run it through my WordPress theme using the format shown here: jQuery: jQuery(document).ready(function( ...

Utilize jQuery to manipulate a subset of an array, resulting in the creation of a new array through the use of

I have a string formatted like this: ItemName1:Rate1:Tax1_ItemName2:Rate2:Tax2:_ItemName3:Rate3:Tax3_ItemName4:Rate4:Tax4 (and so on, up to item 25). My task is to take an index provided by the user (for example, 2), retrieve the item at that index when ...

Transform the JSON object into a TypeScript array

Currently working on a project that requires converting a JSON object into a TypeScript array. The structure of the JSON is as follows: { "uiMessages" : { "ui.downtime.search.title" : "Search Message", "ui.user.editroles.sodviolation.entries" : ...

Gathering information from mapped objects when they are clicked in a React application

Do you know how to retrieve genre.id when a user clicks on a Button and triggers the onClick function? Your assistance is greatly appreciated. ... return ( <div className="App"> <Header /> <div className="A ...

Obtain JavaScript object from WebView in Swift

Currently, I am displaying a webView in my iOS app using Swift. My goal is to retrieve an object from the JavaScript code within the webView. Upon inspecting the console, I discovered that the desired object is named "window.user". However, when attempti ...

Adjusting the line-height and baseline to accommodate various screen sizes on both mobile and desktop

This problem seems to keep coming back for me. I can't figure out what's causing it. Here are two images showing the issue: On desktops: https://i.sstatic.net/AAGbb.png On mobile devices: https://i.sstatic.net/Zk4pc.jpg As you can see, the ...

Retrieving the value from a concealed checkbox

I have been searching everywhere, but I can't seem to find a solution to this particular issue. There is a hidden checkbox in my field that serves as an identifier for the type of item added dynamically. Here's how I've set it up: <inpu ...

Locate the nearest date (using JavaScript)

Searching for the nearest date from an XML file. <?xml version="1.0" encoding="UTF-8"?> <schedule> <layout fromdt="2014-01-01 00:00:00" todt="2014-01-01 05:30:00"/> <layout fromdt="2014-02-01 00:00:00" todt="2014-01-01 05 ...

Encountered an issue when executing python manage.py migrate and python manage.py runserver

form.py This is the form section. from django.contrib.auth.models import User from security_app.models import UserProfileInfo from django import forms class UserForm(forms.ModelForm): password = forms.CharField(widget=forms.PasswordInput()) ...

Position of JSON data response is inaccurate

Currently, I have a function that calls an API from the server in the following manner: getDataSet(callback) { request.open('POST', `${apiPath}`); request.setRequestHeader('Content-Type', 'application/x-ww ...

Arranging an Array by Two Distinct Characteristics

I currently have an array that is grouped and sorted based on the "Program" attribute, which is working well. However, I now need to sort by a different attribute (Deliverable) within each group. Is this possible? If so, how can I achieve it? Below is an ...

The same bootstrap column code shows varying behavior

This week, I delved into learning HTML with the goal of creating my own website using bootstrap. However, I encountered a perplexing error - code that should display two pieces of text on the same line is behaving inconsistently for seemingly identical sni ...

Python script for launching a .html file and automating the process of clicking the submit button

I am currently working with a .html file where I need to send a value using a submit button. Here is how the code looks: <HTML> <HEAD> <TITLE>ABC Corporation</TITLE> </HEAD> <BODY> <FORM ACTION="http://192.168.2.2/cg ...

Stop jQuery popups from wrapping text when resizing the browser window

Whenever a link is clicked, a jQuery popup appears. The popup functions properly in terms of opening and closing, but I would like to ensure that its position remains fixed when resizing the browser window to avoid any wrapping issues. Typically, I use a ...

Retrieving a Table Row from a TableView in Titanium Mobile

Does anyone know where the actual tableViewRows are stored within a TableView? When inspecting the TableView, I can see the headings for the Rows but not the Rows themselves. Can someone point me in the right direction to find where these Rows are contai ...

Verifying password authenticity using AngularJS

Hi there! I'm currently troubleshooting some code that is meant to validate passwords with specific requirements, such as having a certain length and containing special characters. I've managed to set the correct password length, but I'm en ...

Activate Bootstrap tab form with the ability to include sub tabs for added functionality

I have been working on a method to open Bootstrap 3 tabs on my pages based on the URL. For example, if the URL is myurl.com#tab1 (it will open the tab with id #tab1). Here's the code I am using: $(function () { var hash = window.location.hash; ...

The div is set to a position of absolute, causing the overflow-y property to be set to auto. As a

I am facing an issue with a div that has absolute positioning nested inside other divs. If you take a look at the code snippet below from http://jsfiddle.net/d8GYk/, you'll notice the styling properties applied to the div. <div style="position: ...

jQuery - How come my string values are getting cut off?

It's been a while since I last worked with jQuery, and I seem to be missing something obvious that's affecting my calculations. I have various text boxes for Weight, Moisture %, and Number of Filled Squares, as well as a multi-select option for ...

Transform the value of Material-UI DatePicker to seconds

I am trying to figure out how to convert the value from a React Material-Ui datepicker, which currently looks like this: 2021-05-26T01:30, into seconds. Any suggestions on how I can achieve this? PS: My goal is to create a schedule SMS module. Therefore, ...