0

I'm new to Javascript and I'm having problems with this:

$video.css({
    'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg) translateY(' + $body.scrollTop() + 'px)'
});

Only the roation works but not the translateY. So, what I want is to have multiple transforms in there. A usual CSS code would be like:

transform: rotate(10deg) translateY(10px);

What am I doing wrong? Probably missing some symbols.

wupto
  • 47
  • 1
  • 5

2 Answers2

0
$video.css({
    'transform': 'rotate(' + ($body.scrollTop() / bodyHeight * 360) + 'deg),
    'transform': translateY(' + $body.scrollTop() + 'px)' 
});
John williams
  • 654
  • 1
  • 8
  • 22
0

The problem with firefox is that $body.scrollTop() returns 0. Use $(window).scrollTop() instead.

var $video = $('.video'),
  $body = $(document.body),
  $window = $(window),
  bodyHeight = $body.height();

$(window).scroll(function() {
  // Use $(window) instead of $(document.body)
  $video.css({
    'transform': 'rotate(' + ($window.scrollTop() / bodyHeight * 360) + 'deg) ' +
                 'translateY(' + $window.scrollTop() + 'px)'
  });
});
body {
  height: 3000px;
  margin: 0;
}
.video {
  background: black;
  width: 100px;
  height: 70px;
  position: fixed;
  top: 20px;
  left: 20px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body>
  <div class="video"></div>
</body>
Community
  • 1
  • 1
John Bupit
  • 10,406
  • 8
  • 39
  • 75