var elems = $(".billMurray").hover(function(e) {
var len = elems.length;
// parent `.width()` divided by selected element `.length`
var width = elems.parent().width() / len;
// calculate beginning position of each element
var res = $.map(Array(len), function(_, i) {
return !i ? width / 2 : width * i
});
// mouse position
var x = e.clientX;
// select array index using element `.index()`
var index = elems.index(this);
// check if `x` is less than start of element
// position plus element position divided by
// selected element collection `.length` along x axis
// if `true` set sign to `-`, else set sign to `+`
var sign = x < res[index] + (res[index] / len) ? "-" : "+";
$(this).css("transform", "perspective(800px) rotateY(" + sign + "25deg)")
}, function() {
$(this).css("transform", "perspective(800px) rotateY(0deg)")
})
.philWrap {
margin-top: 50px;
}
.billMurray {
width: 25%;
float: left;
text-align: center;
-webkit-transform: perspective(800px) rotateY(0deg);
-moz-transform: perspective(800px) rotateY(0deg);
-o-transform: perspective(800px) rotateY(0deg);
-ms-transform: perspective(800px) rotateY(0deg);
transform: perspective(800px) rotateY(0deg);
-webkit-transition-timing-function: ease-in;
transition-timing-function: ease-in;
-moz-transition: all, 0.5s;
-o-transition: all, 0.5s;
-webkit-transition: all, 0.5s;
transition: all, 0.5s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="philWrap">
<div class="billMurray"><img src="http://fillmurray.com/200/300" alt=""></div>
<div class="billMurray"><img src="http://fillmurray.com/g/200/300" alt=""></div>
<div class="billMurray"><img src="http://fillmurray.com/200/300" alt=""></div>
<div class="billMurray"><img src="http://fillmurray.com/g/200/300" alt=""></div>
</div>