javascript - JQueryUI 可拖动和可调整大小的框问题

标签 javascript jquery html css jquery-ui

我使用 JQueryUI,这是 fiddle example .
我的问题是,正如您在我的 fiddle 中看到的那样,resizable div 中的文本行彼此重叠,而我的 div 只能拖动一次
我该如何解决这个问题?

Javascript

    var DEF_HEIGHT = 100; // the #resizable default height
$( "#resizable" ).resizable({
    containment: 'parent',handles: "se",stop:resizeStop,

  aspectRatio: true,
  resize: function( event, ui ) {        
    var curHeight = (ui.size.height/ DEF_HEIGHT) * 100;

    $(this).css('font-size', curHeight + '%');
  }
}).draggable({containment: 'parent', stop:dragStop});

function dragStop(event, ui){
    convert_to_percentage($(this));
}

function resizeStop(event, ui){
    convert_to_percentage($(this));
}

CSS

    #container {

   background:black;
    position:relative;
    margin:0;
    line-height:0;
    text-align:center;
}
#resizable { 
    width: 200px; 
    height: 100px; 
    padding: 10px; 
    font-size: 100%;
    position:absolute !important;
}

最佳答案

1) 您的行高为 0,这就是行重叠的原因。

2) 您使用了代码中不存在的函数“convert_to_percentage”,这就是您只能拖动它一次的原因

function dragStop(event, ui){
    convert_to_percentage($(this));
}

function resizeStop(event, ui){
    convert_to_percentage($(this));
}

看看这个:http://jsfiddle.net/YxcS8/

关于javascript - JQueryUI 可拖动和可调整大小的框问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21959057/

相关文章:

html - 将图像向下推的CSS问题

php - 实现撤消和重做功能 javascript 和 php

javascript - 浏览器如何识别html中的angularjs标签?

javascript - 将 html 渲染到 View MVC

jquery - 页眉和页脚之间的粘性侧边栏

html - 使标题 div 位于顶层

html - 使用溢出 :hidden 搞乱了 chrome 中的布局

javascript - reactjs 服务和表示组件拆分

javascript - jQuery window.resize() 中的错误?

javascript - 如何使用 require js 将 jquery 库模块集成到 javascript 框架中