Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery random rotate

I have a div with a bunch of images (20) and i like a little rotation on some let say +-2dg

i have try that with no success... all image are rotated equally

/* By default, we tilt all our images -2 degrees */
#gallery2 img {
    -webkit-transform: rotate(-2deg);
    -moz-transform: rotate(-2deg);
    }

/* Rotate all even images 2 degrees */
#gallery2 img:nth-child(even) {
    -webkit-transform: rotate(2deg);
    -moz-transform: rotate(2deg);
    }

/* Don't rotate every third image, but offset its position */
#gallery2 img:nth-child(3n)  {
    -webkit-transform: none;
    -moz-transform: none;
    }

/* Rotate every fifth image by 5 degrees and offset it */
#gallery2 img:nth-child(5n) {
    -webkit-transform: rotate(5deg);
    -moz-transform: rotate(5deg);
    }

So i like to have to code in jquery that will go through all the image in the div and random rotate it + ou - 2 dg

anybody know hot to do that ?

like image 675
menardmam Avatar asked Aug 04 '26 13:08

menardmam


1 Answers

$("#gallery2 img").each( function() {
  var rNum = (Math.random()*4)-2;  
  $(this).css( {   
    '-webkit-transform': 'rotate('+rNum+'2deg)',
    '-moz-transform': 'rotate('+rNum+'2deg)'  
  } );  
} );
like image 119
FatherStorm Avatar answered Aug 06 '26 02:08

FatherStorm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!