Skip to content

Instantly share code, notes, and snippets.

@gitsebs
Forked from anonymous/index.html
Created March 7, 2016 20:11
Show Gist options
  • Save gitsebs/551dcf5ff078cb50e311 to your computer and use it in GitHub Desktop.
Save gitsebs/551dcf5ff078cb50e311 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/ciyekufaca
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style id="jsbin-css">
body {
perspective: 500px;
}
.block {
width:200px;
height:200px;
background: #333;
}
</style>
</head>
<body>
<div class="block"></div>
<script id="jsbin-javascript">
$('body').on('mousemove',function(e){
var elem = $(this),
xR = ((e.pageX/elem.width())*100-50)/5;
yR = -((e.pageY/elem.height())*100-50)/5;
console.log('x: '+xR,' y: '+yR);
$('.block').css({
transform: 'rotate3d(1, 0, 0, '+yR+'deg) rotate3d(0, 1, 0, '+xR+'deg)'
});
});
</script>
<script id="jsbin-source-css" type="text/css">body {
perspective: 500px;
}
.block {
width:200px;
height:200px;
background: #333;
}</script>
<script id="jsbin-source-javascript" type="text/javascript">$('body').on('mousemove',function(e){
var elem = $(this),
xR = ((e.pageX/elem.width())*100-50)/5;
yR = -((e.pageY/elem.height())*100-50)/5;
console.log('x: '+xR,' y: '+yR);
$('.block').css({
transform: 'rotate3d(1, 0, 0, '+yR+'deg) rotate3d(0, 1, 0, '+xR+'deg)'
});
});</script></body>
</html>
body {
perspective: 500px;
}
.block {
width:200px;
height:200px;
background: #333;
}
$('body').on('mousemove',function(e){
var elem = $(this),
xR = ((e.pageX/elem.width())*100-50)/5;
yR = -((e.pageY/elem.height())*100-50)/5;
console.log('x: '+xR,' y: '+yR);
$('.block').css({
transform: 'rotate3d(1, 0, 0, '+yR+'deg) rotate3d(0, 1, 0, '+xR+'deg)'
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment