Scalable and movable images contained within a div

Is there a way to enable resizing and dragging for each image?

Below is a snippet of code that allows users to select which image they would like to display. They have the option to choose multiple images if they prefer.

I am looking to implement functionality that will allow users to resize and drag the selected image within a designated div container.

$(document).ready(function() {
  $('#imajes').change(function() {
    $('.subselector').hide();
    $('.smallimages').hide();
    $('#' + $(this).val()).show();

  });

  $('.smallimages').hide();
  var id = $(this).attr('id');
  var val = $(this).val();


  $('#dog').on('change', function() {

    $("#bulldogimges").css('display', (this.value == 'bulldog') ? 'block' : 'none');

  });

  $('img').on('click', function() {
    $('#fotos').append('<img class="modal-content" src="' + $(this).attr('src') + '">');
    $('#fotos').draggable();
    $('#imgdisplay').resizable();

  });

});
.imgcontainerss {
  float: left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>


<div id="fotos">
  <img class="modal-content" id="imgdisplay" />
</div>

<select id="imajes">
  <option value="">Choose Image</option>
  <option value="dog">Dog</option>

</select>
<select id="dog" name="subselector" class="subselector" style="display:none">
  <option value="">Choose an item</option>
  <option value="bulldog">Bulldog</option>

</select>


<div style='display:none;' id="bulldogimges" class="smallimages">
  <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif">
    <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55">
  </div>
  <div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif">
    <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55">
  </div>
</div>

Answer №1

Revise fiddle code and included draggable and resizable features for images

To enlarge and resize the image, simply click on it.

$(document).ready(function() {
  $('#imajes').change(function() {
    $('.subselector').hide();
    $('.smallimages').hide();
    $('#' + $(this).val()).show();

  });
  
    $('.smallimages').hide();
    var id = $(this).attr('id');
    var val = $(this).val();


$('#dog').on('change', function() {
  
  $("#bulldogimges").css('display', (this.value == 'bulldog') ? 'block' : 'none');

});

$('img').on('click', function() {
    $('#fotos').append('<div class="imgdrag"><img class="modal-content" src="' + $(this).attr('src')+ '"/></div>'); $('.imgdrag').draggable();
$('#fotos').droppable();
           $('.modal-content').resizable();


});

  
  
});
.imgcontainerss{
    float:left;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" 
href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/>

<div id="fotos" ><img class="modal-content" id="imgdisplay" /></div>

<select id="imajes">
        <option value="">Choose Image</option>
        <option value="dog">Dog</option>
       
    </select> <select id="dog" name="subselector" class="subselector" style="display:none">
  <option value="">Choose an item</option>
  <option value="bulldog">Bulldog</option>
 
</select>


<div style='display:none;' id="bulldogimges" class="smallimages">
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/pT78gE6pc.gif">
    <img src="https://torcdesign.com/clipart/pT78gE6pc.gif" alt="Smiley face" width="55" height="55">
  </div>
<div class="imgcontainerss" data-image="https://torcdesign.com/clipart/LiKkRqkeT.gif">
    <img src="https://torcdesign.com/clipart/LiKkRqkeT.gif" alt="Smiley face" width="55" height="55">
  </div></div>

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

Removing duplicate data from Table TD and TR elements using Jquery

I am working on an HTML table and I need to remove duplicate values in each <tr> and <td> data cell. Here is a snippet of my code: <table width="100%" id="l2table"> <thead><tr> ...

Mastering hot reloading in React when using Dotnet and DockerorAchieving seamless hot reloading in

I have been working on getting hot reloading to function properly with React, Docker, and Dotnet. However, my research has shown that only static rendering is compatible with Docker. As a result, I find myself having to run the command docker -t build {Na ...

Check to see if the cursor is positioned on the newly created raphael element without requiring a new mouse

After creating a new element using Raphael.js, I have noticed that hover events do not trigger on Chrome (42.0.2311.90) or Internet Explorer (11.0.8) when the element is under an idle cursor. However, Firefox (31.0, 32.0.2, and 37.0.2) works as intended. ...

Keep an ear out for socket.io within an Angular application

I am trying to connect socket.io with my angular application. I have come across some examples of creating a service that can be accessed by the controller, and I understand that part. However, I am looking for a solution where all controllers can respond ...

Is it possible to retrieve the complete source HTML code of a webpage that is dynamically generated by JavaScript using Java and WebDriver?

I'm new to the world of programming and I've encountered a challenge that I need to overcome. I'm attempting to retrieve the HTML source code of a webpage using the Java / Webdriver method getPageSource(). However, the page seems to be dynam ...

Navigating with React Router Dom and parsing objects in search parameters

Currently, I am utilizing React Router Dom v6 and require the ability to retain object search parameters within the URL. My current approach involves: const [searchParams, setSearchParams] = useSearchParams(); const allSearchParams = useMemo(() => { ...

Using Javascript to initialize events based on a variable

This particular plugin is structured in the following way: (function($){ var defaults = { param1:null, param2:null }; var methods = { init:function(params) { var ...

Retrieve information from a pop-up modal and showcase it in a table within the main controller

How can we transfer data from a modal to a main controller table and update the table on clicking the generate button in the modal? Currently, I am able to retrieve input text data from the generate button click event but the table is not being updated w ...

What is the process for creating a custom plugin for Microsoft Excel that can be downloaded elsewhere, rather than through the official Excel marketplace?

We're in the process of creating a plugin for Excel, but it seems that the only way to make it available is through the Excel Add-in Store, which involves complex partnerships. Is there any alternative method to allow users to download and access the ...

displaying data once "other" is chosen from a dynamic chart

I am having an issue with a dynamic table where I have a dropdown list with the option "other", and I want to display additional input when "other" is selected. Currently, the function I have only hides the input that is always visible and does not show ...

Creating a unique button design that incorporates a select tag and utilizes a dynamic percentage width

How can I keep a custom button positioned 20 pixels away from the right side of a select dropdown menu with a fixed width percentage? Using percentages in the background-position property makes the button move too far when the window is large. Setting the ...

Ways to swap webpack-dev-server for alternative servers such as express or apache

After using vue-cli to scaffold a Vue app, I am looking to set up a new web server instead of webpack-dev-server. I am interested in having a separate configuration file to customize the server settings, similar to using Node Express for production deploym ...

Generating unique identifiers for jQuery carousel

<div id="container_01"> <div class="pikachoose"> <ul id="pikame" class="jcarousel-skin-pika"> <li> <img id="main_photo" name="main_photo" src="image.jpg" width="520" height="380" class="del ...

Dynamically update CSS class properties with another

I have incorporated a bootstrap CSS tooltip class that is defined as follows: .tooltip{display:none;color:#000;text-align:left;} .tooltip.in{opacity:0.9;z-index:1030;height:auto;display:block} .tooltip.top{margin-top:-10px;text-align:center} ...

Incorporating a dropdown feature into the navigation bar

Greetings, I am currently learning on the job as I work on a new website for my family business. I am struggling to make the drop-down navigation menu function properly on both desktop and mobile. I want it to have a simple design similar to the main nav ...

How to include a javascript file in a vuejs2 project

Just starting out with the Vue.js framework and I've hit a snag trying to integrate js libraries into my project. Would greatly appreciate any assistance! By the way, I attempted adding the following code to my main.js file but it didn't have th ...

"Ensuring a DIV element has a height of 100% within

Is there a way to set and enforce a div's height to be 100% of the browser window, another div, or a table cell without resorting to complicated hacks found on Stack Overflow or other websites? ...

Jquery Ajax post function returning empty values

I'm currently learning the Jquery Ajax method. I have successfully posted a JSON string using the $.post method, but am encountering a 500 error when trying to use the $.ajax method. Any suggestions would be greatly appreciated. ---- Using $.post Met ...

Nested Bootstrap structure with a column containing two sub-columns

I am attempting to create a grid layout using bootstrap. The layout should consist of a full 12 column layout on desktop, with an 8 column grid and a 4 column grid within it. The 8 column grid will contain an image/text, while the 4 column grid will have t ...

The request for `/` cannot be fulfilled while serving an Angular application with Express and Node.js

I've been attempting to host an Angular application using Node.js, but I keep encountering the error message "Cannot GET /" displayed on the page. Despite trying various solutions, I have been unable to resolve this issue. Does anyone have any suggest ...