简体   繁体   English

希望在滚动时来回旋转图像

[英]Looking to rotate an image back and forth upon scrolling

Looking to rotate an image 180 degrees clockwise one direction upon scrolling, then as you scroll backup the other direction it would rotate 180 degrees counterclockwise. 希望在滚动时将图像向一个方向顺时针旋转180度,然后在滚动备份时向另一方向滚动,图像将逆时针旋转180度。

This guy does it, but it's continuous. 这个家伙做到了,但它是连续的。 I'm looking for it to stop or lock-in at 180 one way then 180 the other as you scroll or back to 0. So basically it's pointing in the direction you are scrolling. 我正在寻找它以一种方式停止或锁定,然后在您滚动或返回0时以另一种方式停止或锁定在180。所以基本上,它指向的是您滚动的方向。 By default it would start by pointing downwards. 默认情况下,它将从向下指向开始。

Rotation Reference 旋转参考

$(function() {
     var $plane = $('.plane'); // Cache your elements!

     $(window).scroll(function() {
         if ($(this).scrollTop() > 10) {
             $plane.css({transform: 'rotate('+ window.pageYOffset%180 +'deg)'});
         } elseif ($(this).scrollTop() < 10); {
             $plane.css({transform: 'rotate('+ window.pageYOffset%-180 +'deg)'});
         }
     });

});

This one works for me on FF and Chrome: 这对我在FF和Chrome上适用:

$(function() {

  var $plane = $('.plane'); // Cache your elements!

  $(window).scroll(function() {  
      $plane.css({transform: 'rotate('+ (180*window.pageYOffset/(document.body.clientHeight - window.innerHeight)) +'deg)'}); 
  });

});

Icon is rotated from 0 to 180 as you progress toward the end of the page, and back to zero as you go back. 当您向页面末尾前进时,图标从0旋转到180,然后向后退回到零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM