JSFiddle - React, Tailwind, and code Playground
rotate directive
by Andrew Pougher
HTML
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="https://code.angularjs.org/1.4.8/angular.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.css">
<script src="https://raw.githubusercontent.com/godswearhats/jquery-ui-rotatable/master/jquery.ui.rotatable.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<div ng-controller="spinCntl" class="container" style="min-height:90vh">
<div class="row" style="min-height:100%">
<div resizable resizeme="savecoords()"></div>
</div>
<div id="moveAlert" class="alert alert-success fade" role="alert"> {{notice || "waiting"}}</div>
</div>
CSS
.container{ min-height: 100vh;background:#eee}
div[resizable] {
border: 1px solid #eeeeee;
width: 67vw;
min-width: 2vw;
min-height: 100px;
background-size: cover;
background-image: url("http://i.imgur.com/djijjlr.jpg");
}
.handle.is-dragging {
z-index: 100;
box-shadow: inset 0 0 0 3px;
cursor: none;
-webkit-transition: box-shadow 0;
transition: box-shadow 0
}
.draggable {
position: relative;
display: -moz-inline-stack;
display: inline-block;
vertical-align: top;
zoom: 1;
*display: inline;
cursor: hand;
cursor: pointer;
}
.resizable {
width: 100px;
border: 1px solid #bb0000;
}
.resizable img {
width: 100%;
}
.ui-resizable-handle {
background: #f5dc58;
border: 1px solid #FFF;
width: 15px;
height: 15px;
border-radius: 50%;
z-index: 2;
opacity: 0.3;
transition: all 0.3s ease 0s;
}
.ui-resizable-handle:hover {
opacity: 1
}
.ui-resizable-se {
right: -8px;
bottom: -8px;
}
.ui-rotatable-handle {
background: #f5dc58;
border: 1px solid #FFF;
border-radius: 50%;
-moz-border-radius: 50%;
-o-border-radius: 50%;
-webkit-border-radius: 50%;
cursor: pointer;
opacity: 0.4;
width: 23px;
height: 23px;
left: 47%;
margin: 0 0 0 -5px;
position: absolute;
top: -9px;
transition: all 0.3s ease 0s;
}
.ui-rotatable-handle:before {
content: "\f021";
font-family: FontAwesome;
color: #ffffff;
font-size: 16px;
padding-right: 0.5em;
position: absolute;
top: -1px;
left: 4px;
}
.ui-rotatable-handle:hover {
opacity: 1;
}
.fade {
opacity: 0;
-webkit-transition: opacity 0.15s linear;
-moz-transition: opacity 0.15s linear;
-o-transition: opacity 0.15s linear;
transition: opacity 0.15s linear;
}
.fade.in {
opacity: 1;
}
#moveAlert {
position: fixed;
top: 1px;
left: 20%
}
JavaScript
var app = angular.module('drewApp', []);
app.controller('spinCntl', function($http, $scope, $timeout) {
$scope.savecoords = function() {
$scope.notice = "";
$timeout(function() {
$scope.notice = "Ready to proof?";
$("#moveAlert").addClass("in");
}, 30);
$timeout(function() {
$("#moveAlert").removeClass("in");
}, 3800);
};
});
app.directive('resizable', function() {
return {
restrict: 'A',
scope: {
callback: '&resizeme'
},
link: function postLink(scope, elem, attrs) {
elem.draggable({
containment: ".container",
cursor: "move",
opacity: 0.3
});
elem.resizable();
elem.rotatable();
elem.on('resizestop', function(evt, ui) {
if (scope.callback) {
scope.callback();
}
});
}
};
});