我正在制定像平面图一样的项目。该项目与JQuery 100%合作,但我知道我想与angularjs集成,因为我需要将jquery函数转换为angularjs指令。
下面我发布了我的jquery代码,请任何人帮我转换。
提前致谢...
.JS
$(document).ready(function(){
//Counter
counter = 0;
//Make element draggable
$(".drag").draggable({
helper:'clone',
containment: 'frame',
//When first dragged
stop:function(ev, ui) {
var pos=$(ui.helper).offset();
objName = "#clonediv"+counter
$(objName).css({"left":pos.left,"top":pos.top});
$(objName).removeClass("drag");
//When an existiung object is dragged
$(objName).draggable({
containment: 'parent',
stop:function(ev, ui) {
var pos=$(ui.helper).offset();
console.log($(this).attr("id"));
console.log(pos.left)
console.log(pos.top)
}
});
}
});
//Make element droppable
$("#frame").droppable({
drop: function(ev, ui) {
if (ui.helper.attr('id').search(/drag[0-9]/) != -1){
counter++;
var element=$(ui.draggable).clone();
element.addClass("tempclass");
$(this).append(element);
$(".tempclass").attr("id","clonediv"+counter);
$("#clonediv"+counter).removeClass("tempclass");
//Get the dynamically item id
draggedNumber = ui.helper.attr('id').search(/drag([0-9])/)
itemDragged = "dragged" + RegExp.$1
console.log(itemDragged)
$("#clonediv"+counter).addClass(itemDragged);
}
}
});
});
function readURL(event){
var getImagePath = URL.createObjectURL(event.target.files[0]);
$('#frame').css('background-image', 'url(' + getImagePath + ')');
}
.CSS
body {
text-align: center;
z-index: 1;
}
#wrapper {
text-align: left;
width: 720px;
margin-left: auto;
margin-right: auto;
}
#options{
width: 700px;
height: 90px;
border: 1px solid black;
}
#frame{
margin-top: 25px;
width: 700px;
height: 550px;
background-image: url('');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
border: 1px solid black;
margin-left: 0px;
position: relative;
z-index: 10;
}
#tbldevs{
border:1px solid black;
width:80%;
margin-left:50px;
margin-top:10px;
}
#tbldevs th{
text-align:center;
height:50px;
width:50px;
}
#tbldevs td{
height:50px;
}
#drag1 {
margin-left: 15px;
margin-top: 15px;
/* background-image: url("../images/cf_32x32.png"); */
width: 32px;
height: 32px;
border: 2px solid black;
border-radius: 50%;
float: left;
z-index: 25;
}
#drag2 {
margin-left: 79px;
margin-top: 15px;
/* background-image: url("../images/cf_32x32.png"); */
width: 60px;
height: 32px;
border: 2px solid black;
z-index: 25;
}
.ui-draggable-helperMoving {
border: 1px dotted #000;
padding: 6px;
background: #fff;
font-size: 1.2em;
width:100px;
height:100px;
}
.ui-draggable-helperStoped {
border: 1px solid #000;
width:5px;
height:5px;
}
/* classes for dragged stuff */
.dragged1 {
position: fixed;
/* background-image: url("../images/cf_32x32.png"); */
width: 32px;
height: 32px;
border: 2px solid black;
border-radius: 50%;
}
.dragged2 {
position: fixed;
/* background-image: url("../images/cf_32x32.png"); */
width: 60px;
height: 32px;
border: 2px solid black;
}
/*.dragged3 {
position:absolute;
background-image: url("../images/fla_32x32.png");
width:32px;
height:32px;
}
.dragged4 {
position:absolute;
background-image: url("../images/flex_32x32.png");
width:32px;
height:32px;
}
.dragged5 {
position:absolute;
background-image: url("../images/pdf_32x32.png");
width:32px;
height:32px;
}
.dragged6 {
position:absolute;
background-image: url("../images/ps_32x32.png");
width:32px;
height:32px;
}
#element{
border:1px solid red
}*/
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-script-type" content="text/javascript" />
<meta http-equiv="content-style-type" content="text/css" />
<title>Where have I been? - Demo</title>
<meta name="description" content="Where have I been?" />
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.4.2");
google.load("jqueryui", "1.7.2");
</script>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" media="all" />
<script src="js/script.js"></script>
</head>
<body>
<input type='file' id='getval' name="background-image" onchange="readURL(event)" /><br/><br/>
<div id="wrapper">
<div id="options">
<div id="drag1" class="drag"></div> <!-- end of drag1 -->
<div id="drag2" class="drag"></div> <!-- end of drag2 -->
</div><!-- end of options -->
<div id="frame">
</div><!-- end of frame -->
</div><!-- end of wrapper -->
</body>
</html>