Using two different CSS transforms at once

I am working on a script to adjust the image using left and right transforms depending on the position of the cursor.
There is also CSS to enlarge the image on hover.

// JavaScript source code
var catchX = 0,
    catchY = 0,
    x = 0,
    y = 0,
    burn = 1 / 28;

function imageWatch() {
    x += (catchX - x) * burn;

    translate = 'translate(' + x + 'px, ' + y + 'px)';

    $('.image-area img').css({
        '-webit-transform': translate,
        '-moz-transform': translate,
        'transform': translate
    });

    window.requestAnimationFrame(imageWatch);
}

$(window).on('mousemove click', function (e) {

    var mouseX = Math.max(-100, Math.min(100, $(window).width() / 2 - e.clientX));
    catchX = (26 * mouseX) / 100;

});

imageWatch();
     
html,body { height:100%}
body {margin: 0; padding: 0;}
*, *::before, *::after {
  content:"\0020";
  box-sizing: border-box;
}
.poster {
  display: inline-block;
  width: 32vw;
  height: 100vh;
  position:relative;
  overflow:hidden !important
}
 .image-area {
            position: absolute;
            width: 100%;
            height: 100vh;
            opacity: .24;
            transition: 2.5s ease;
        }

.image-area {
            opacity: 1;
        }


.image-area > img {
            margin-top: -312px;
            margin-left: -913px;
            width: auto;
            /* height: auto */
            height: 1000px;
            transform: scale(1,1);
            transition:8s all;
        }

.poster:hover .image-area > img {
            transform: scale(1.3,1.3)
        }
        
        
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="poster">
    <div class="image-area">
         <img class="poster" src="https://vignette1.wikia.nocookie.net/logopedia/images/f/fc/Sky_Believe_in_better_logo.jpg/revision/latest?cb=20110910152552" alt="Sky" />
    </div>
</div>

<div class="poster">
    <div class="image-area">
         <img class="poster" src="https://vignette1.wikia.nocookie.net/logopedia/images/f/fc/Sky_Believe_in_better_logo.jpg/revision/latest?cb=20110910152552" alt="Sky" />
    </div>
</div>

<div class="poster">
    <div class="image-area">
         <img class="poster" src="https://vignette1.wikia.nocookie.net/logopedia/images/f/fc/Sky_Believe_in_better_logo.jpg/revision/latest?cb=20110910152552" alt="Sky" />
    </div>
</div>
   
Run codeHide result

My JS uses the transform property, just like my CSS, so that it will increase the hover. I think this is a problem.

If you remove the transform from CSS, the script works fine, but I need transition:8s allto zoom in on the mouseover, and also to align it with the cursor.

This SO informed me that you can have two conversion properties, but they should be on the same line. How do I do this with Javascript?


jsFiddle

+4
1

transform - , CSS , , CSS transition-duration transform-functions, transform.

js, , , .

- , scale .

, <img>, .

// JavaScript source code
var catchX = 0,
  catchY = 0,
  x = 0,
  y = 0,
  burn = 1 / 28;

function imageWatch() {
  x += (catchX - x) * burn;

  translate = 'translate(' + x + 'px, ' + y + 'px)';

  $('.image-area img').css({
    '-webit-transform': translate,
    '-moz-transform': translate,
    'transform': translate
  });

  window.requestAnimationFrame(imageWatch);
}

$(window).on('mousemove click', function(e) {

  var mouseX = Math.max(-100, Math.min(100, $(window).width() / 2 - e.clientX));
  catchX = (26 * mouseX) / 100;

});

imageWatch();
html,
body {
  height: 100%
}

body {
  margin: 0;
  padding: 0;
}

*,
*::before,
*::after {
  content: "\0020";
  box-sizing: border-box;
}

.poster {
  display: inline-block;
  width: 32vw;
  height: 100vh;
  position: relative;
  overflow: hidden !important
}

.image-area {
  position: absolute;
  width: 100%;
  height: 100vh;
  opacity: .24;
  transition: 2.5s ease;
}

.image-area {
  opacity: 1;
}

.image-area img {
  margin-top: -312px;
  margin-left: -913px;
  width: auto;
  /* height: auto */
  height: 1000px;
 /* here we can remove the transition */
}


/* scaling on hover is only applied on the parent elmt */

.image-area>.scaler {
  transform: scale(1, 1);
  transition: 8s transform;
}

.poster:hover .image-area>.scaler {
  transform: scale(1.3, 1.3);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="poster">
  <div class="image-area">
    <!-- the scaling wrapper-->
    <div class="scaler">
      <img class="poster" src="https://vignette1.wikia.nocookie.net/logopedia/images/f/fc/Sky_Believe_in_better_logo.jpg/revision/latest?cb=20110910152552" alt="Sky" />
    </div>
  </div>
</div>

<div class="poster">
  <div class="image-area">
    <!-- the scaling wrapper-->
    <div class="scaler">
      <img class="poster" src="https://vignette1.wikia.nocookie.net/logopedia/images/f/fc/Sky_Believe_in_better_logo.jpg/revision/latest?cb=20110910152552" alt="Sky" />
    </div>
  </div>
</div>

<div class="poster">
  <div class="image-area">
    <!-- the scaling wrapper-->
    <div class="scaler">
      <img class="poster" src="https://vignette1.wikia.nocookie.net/logopedia/images/f/fc/Sky_Believe_in_better_logo.jpg/revision/latest?cb=20110910152552" alt="Sky" />
    </div>
  </div>
</div>
Hide result
+5

Source: https://habr.com/ru/post/1690559/


All Articles