使用css自定义覆盖div周围 - jQuery可自定义句柄可调整大小

时间:2017-10-07 05:18:56

标签: javascript jquery css jquery-ui jquery-plugins

您好我在我的项目中使用jquery resizable,rotate()[https://cdn.jsdelivr.net/gh/godswearhats/jquery-ui-rotatable@1.1/jquery.ui.rotatable.min.js]

所以当这个函数调用i得到句柄来旋转和调整div的大小。

$( function() {

        var inputLocalFont = document.getElementById("user_file");
        inputLocalFont.addEventListener("change",previewImages,false);

        function previewImages(){
            var fileList = this.files;

            var anyWindow = window.URL || window.webkitURL;

                for(var i = 0; i < fileList.length; i++){
                  var objectUrl = anyWindow.createObjectURL(fileList[i]);
                  $('.new-multiple').append('<div class="img-div"><img src="' + objectUrl + '" class="newly-added" /></div>');
                  window.URL.revokeObjectURL(fileList[i]);
                }

        $( ".img-div" ).draggable();
	      $('.img-div').rotatable();
        $( ".img-div" ).resizable({aspectRatio:true});
              $(".newly-added").on("click", function(e) {
	   $(".newly-added").removeClass("img-selected");
       $(this).addClass("img-selected");
	    e.stopPropagation()
    });

	  $(document).on("click", function(e) {
		if ($(e.target).is(".newly-added") === false) {
		  $(".newly-added").removeClass("img-selected");
		}
	  });
              
              } 
});
.new-multiple{
  width:400px !important;
  height:400px !important;
  background:white;
  border:2px solid red;
  overflow:hidden;
  }
  
  
 .img-div{
   width:200px;
   height:200px;
 } 
 .newly-added{
    width:100%;
    height:100%;
} 

.img-selected{
  box-shadow: 1px 2px 6px 6px rgb(206, 206, 206);
  border:2px solid rgb(145, 44, 94);
}
.ui-resizable-handle.ui-resizable-se.ui-icon.ui-icon-gripsmall-diagonal-se {
    background-color: white;
    border: 1px solid tomato;
}
.ui-rotatable-handle.ui-draggable {
    background-color: white !important;
    border: 1px solid tomato;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">  
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/godswearhats/jquery-ui-rotatable@1.1/jquery.ui.rotatable.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script type="text/javascript"  src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>	
<script src="https://cdn.jsdelivr.net/gh/godswearhats/jquery-ui-rotatable@1.1/jquery.ui.rotatable.min.js"></script>
<input   name="user_file[]" id="user_file" style="position: relative;overflow: hidden" multiple="" type="file">

 <div class="new-multiple"></div>

https://jsfiddle.net/vd11qyzv/21/

因此,当我上传图片时,我会得到像这样的控制句柄

enter image description here

但我想放置像这样的自定义控件句柄

enter image description here

我如何使用css和jquery实现这一目标。请帮忙

1 个答案:

答案 0 :(得分:1)

在resizable中设置<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>选项后,您可以使用CSS管理它们。他们的风格和位置。

CSS代码段

handles

<强>的JavaScript

.ui-resizable-handle {
  border: 0;
  border-radius: 50%;
  background-color: #00CCff;
  width: 14px;
  height: 14px;
}

.ui-resizable-nw {
  top: -7px;
  left: -7px;
}

.ui-resizable-ne {
  top: -7px;
  right: -7px;
}

.ui-resizable-e {
  top: calc(50% - 7px);
  right: -7px;
}

.ui-resizable-w {
  top: calc(50% - 7px);
  left: -7px;
}

.ui-resizable-sw {
  bottom: -7px;
  left: -7px;
}

.ui-resizable-se {
  right: -7px;
  bottom: -7px;
}

.ui-resizable-se.ui-icon {
  display: none;
}

.ui-rotatable-handle {
  background-size: 14px;
  background-repeat: no-repeat;
  background-position: center;
  border: 0;
  border-radius: 50%;
  background-color: #00CCff;
  margin-left: calc(50% - 9px);
  bottom: -5px;
  width: 18px;
  height: 18px;
}

工作示例:https://jsfiddle.net/Twisty/s99kxydw/