2016-07-28 98 views
1

想知道是否有人可以提供帮助。我在网站上使用jQuery可调整大小。我想使用伪类将调整大小/可调整大小的对象显示为通知样式徽章,每次调整项目大小时都应该更新。 CSS不是问题,它获取大小数据并显示我遇到的问题。任何想法如何把这个关掉?任何帮助都感激不尽。我在下面的代码片段中有错误,所以这里有一个小工具可以使用。使用jQuery调整大小来显示项目的大小

https://jsfiddle.net/adrian_babb/xwaokufj/

<ul id="icon_menu"> 
    <li class="draggable"></li> 
</ul> 

draggable.ui-resizable:after { 
content: ""; 
position: absolute; 
top: -5px; 
right: -5px; 
font-size: .7em; 
background-color: #5f6a72; 
color: #ffffff; 
width: 20px; 
height: 20px; 
text-align: center; 
line-height: 20px; 
border-radius: 50%; 
} 

<script>   
$(document).ready(function($) { 

$(".droppable").droppable({ 
    accept: '.draggable', 
    drop: function(event, ui) { 
     var $clone = ui.helper.clone(); 
     if (!$clone.is('.inside-droppable')) { 
      $(this).append($clone.addClass('inside-droppable').draggable({ 
       containment: '.droppable', 
       scroll: false, 
       tolerance: 'pointer', 
       position: 'relative', 
      })); 

      $clone.resizable({ 
       aspectRatio: 'true', 
       ghost: 'true', 
       handles: 'ne, nw, se, sw', 
       maxHeight: 200, 
       maxWidth: 200, 
       minHeight: 30, 
       minWidth: 30 
      }); 
     } 
    } 
}); 
$(".draggable").draggable({ 
    helper: 'clone', 

$(document).ready(function($) { 
 

 
    $(".droppable").droppable({ 
 
     accept: '.draggable', 
 
     drop: function(event, ui) { 
 
      var $clone = ui.helper.clone(); 
 
      if (!$clone.is('.inside-droppable')) { 
 
       $(this).append($clone.addClass('inside-droppable').draggable({ 
 
        containment: '.droppable', 
 
\t \t \t \t \t scroll: false, 
 
\t \t \t \t \t tolerance: 'pointer', 
 
\t \t \t \t \t position: 'relative', 
 
       })); 
 

 
       $clone.resizable({ 
 
\t \t \t \t \t aspectRatio: 'true', 
 
\t \t \t \t \t ghost: 'true', 
 
\t \t \t \t \t handles: 'ne, nw, se, sw', 
 
\t \t \t \t \t maxHeight: 200, 
 
\t \t \t \t \t maxWidth: 200, 
 
\t \t \t \t \t minHeight: 30, 
 
\t \t \t \t \t minWidth: 30 
 
       }); 
 
      } 
 
     } 
 
    }); 
 
    $(".draggable").draggable({ 
 
     helper: 'clone', 
 
\t \t revert:"invalid", 
 
\t \t scroll: false 
 
    }); 
 
    });
#icon_menu { 
 
\t width: 200px; 
 
\t height: auto; 
 
\t float: right; 
 
} 
 

 
#icon_menu li { 
 
\t width: 45px; 
 
\t height: 45px; 
 
\t position: relative; 
 
} 
 

 
.draggable { 
 
\t width: 45px; 
 
\t height: 45px; 
 
\t border-radius: 50%; 
 
\t background: rgba(127, 214, 236, 0.5); 
 
} 
 

 
.droppable { 
 
\t width: 200px; 
 
\t height: 100px; 
 
    border: 1px solid #000000; 
 
    float: left; 
 
} 
 

 
draggable.ui-resizable:after { 
 
\t content: ""; 
 
\t position: absolute; 
 
\t top: -5px; 
 
\t right: -5px; 
 
\t font-size: .7em; 
 
\t background-color: #5f6a72; 
 
\t color: #ffffff; 
 
\t width: 20px; 
 
\t height: 20px; 
 
\t text-align: center; 
 
\t line-height: 20px; 
 
\t border-radius: 50%; 
 
}
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
 
<ul id="icon_menu"> 
 
    <li class="draggable"></li> 
 
</ul>

+0

请尝试添加小提琴或内容片段在你的情况... –

+0

片段没有按”运行。 – ksav

+0

抱歉我的代码段有脚本错误。不知道为什么所以我添加了一个似乎工作正常的小提琴 – user3433046

回答

0

您必须jQueryUI的库包括在内,使投掷的()和拖动()工作。你已经做了之后,有一个方法停止,当resize事件完成时调用,像这样:

$element.resizable({ 
    handles: 'e', 
    ghost: true, 
    delay: 200, 
    helper: "overmoused", 
    minWidth: 20, 
    start: function(e, ui) {}, 
    resize: function() {}, 
    stop: function(e, ui) { 
    console.log(ui.originalSize.width, ui.size.width) 
    } 
}); 
+0

对不起,我发布了问题之前,我已经妥善挑选外部库,现在全部排序。感谢您的回答,我将如何在CSS中使用这个尺寸:after属性。 – user3433046

+0

1)或者不是:之后,你创建一个元素,然后在stop方法中设置它的属性 – webdevfagbok

+0

2)[使用像这样的东西](http://stackoverflow.com/questions/5041494/selecting-and-manipulating- CSS-伪元素 - 例如-AS-之前和之后,全光照) – webdevfagbok