Skip to content

Instantly share code, notes, and snippets.

@sm-abdullah sm-abdullah/index.html Secret
Last active Dec 21, 2015

Embed
What would you like to do?
Virtual Try-On for Eye Glasses using JQuery HTML and CSS3
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<style>
#draggable1 { width: 150px; height: 150px; padding: 0.5em; }
</style>
<script>
$(function() {
$( "#draggable" ).draggable({ containment: "parent" });
$('#inc').click(function () {
var w = $("#draggable").width() ;
$("#draggable").width(w+10);
});
$('#dec').click(function () {
var w = $("#draggable").width() ;
$("#draggable").width(w-10);
});
$('#rota').click(function () {
var sdf = getRotationDegrees($("#draggable"));
sdf = sdf - 5;
$("#draggable").css('-webkit-transform','rotate('+sdf +'deg)');
$("#draggable").css({ '-moz-transform':'rotate(' + sdf+ 'deg)'});
$("#draggable").css({ '-ms-transform':'rotate(' + sdf+ 'deg)'});
$("#draggable").css({ '-o-transform':'rotate(' + sdf+ 'deg)'});
$("#draggable").css({ 'transform':'rotate(' + sdf+ 'deg)'});
});
$('#rotp').click(function () {
var sdf = getRotationDegrees($("#draggable"));
sdf = sdf + 5;
$("#draggable").css('-webkit-transform','rotate('+sdf +'deg)');
$("#draggable").css({ '-moz-transform':'rotate(' + sdf+ 'deg)'});
$("#draggable").css({ '-ms-transform':'rotate(' + sdf+ 'deg)'});
$("#draggable").css({ '-o-transform':'rotate(' + sdf+ 'deg)'});
$("#draggable").css({ 'transform':'rotate(' + sdf+ 'deg)'});
});
function getRotationDegrees(obj) {
var matrix = obj.css("-webkit-transform") ||
obj.css("-moz-transform") ||
obj.css("-ms-transform") ||
obj.css("-o-transform") ||
obj.css("transform");
if(matrix !== 'none') {
var values = matrix.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
var angle = Math.round(Math.atan2(b, a) * (180/Math.PI));
} else { var angle = 0; }
return angle;
}
});
</script>
</head>>
<body>
<div id="ryon_image_small" style="height:320px;width:240px; display: block; background-image: url('sample.jpg');">
<img id="draggable" src="glass.png" style="cursor: move;width:160px;position: relative; left: 37px; top: 89px;"/>
</div>
<a id="inc" href="#"> Increase size </a>
<a id="dec" href="#"> decrease size </a>
<a id="rotp" href="#"> rotate clockwise </a>
<a id="rota" href="#"> rotate anti clockwise </a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.