【问题标题】:How do I set'draggable' and'resizable' at the same time in jquery?如何在 jquery 中同时设置“可拖动”和“可调整大小”?
【发布时间】:2021-04-28 07:27:32
【问题描述】:

jquery中如何同时设置'draggable'和'resizable'?

以下代码只移动一次,不再移动。

我想继续移动和调整大小,我该怎么办?

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="style/result.css?v=1.3" />
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<%@ page import = "java.io.*" %> 

<script type="text/javaScript" >

$(function(){ 
    var counts = [0];  
    $(".dragImg").draggable({
        helper: "clone",
        //Create counter
        start: function() { counts[0]++; }
    }); 
    $("#dropHere1").droppable({
        drop: function(e, ui){
            $(this).append($(ui.helper).clone());
            
            $(ui.helper).clone().draggable();
            $("#dropHere1 .dragImg").addClass("item-"+counts[0]); 

            $("#dropHere1 .item-"+counts[0]).removeClass("dragImg ui-draggable ui-draggable-dragging");

            $(".item-"+counts[0]).dblclick(function() {
                $(this).remove();
            }).resizable();
        }
    });
});
</script>
<img src="https://t1.daumcdn.net/cfile/tistory/234774445960F69422" class="dragImg" width="90" height="90" >
<div id="dropHere1" ></div>
    

【问题讨论】:

  • 请查看link
  • 这个问题是 10 年前发布的
  • 这能回答你的问题吗? Jquery Draggable AND Resizable
  • 链接中的代码不起作用。这是我的代码(上),我应该如何应用它?

标签: javascript html jquery css


【解决方案1】:

首先我们调用 .draggable() 函数使 DIV 可拖动,然后我们调用 resizable()。为此,我们只需定义:

$('#dragResizeDiv')
    .draggable()
    .resizable();

您可能希望在开始/停止/调整大小事件上定义回调函数。

  $('#resizeDiv')
        .resizable({
            start: function(e, ui) {
                alert('resizing started');
            },
            resize: function(e, ui) {
            
            },
            stop: function(e, ui) {
                alert('resizing stopped');
            }
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-22
    相关资源
    最近更新 更多