繁体   English   中英

停止jQuery舍入到.css()上的小数点后一位

[英]Stop jQuery rounding to the nearest decimal on .css()

如何停止jQuery舍入到Transfrom: translateY上最接近的十进制值Transfrom: translateY 由于iPad上的Safari变得非常不稳定,因此会导致Safari的性能问题

$(window).on("load resize scroll",function(e){

if ($(window).width() > 768) {
  var item = $('.sticky-stuff');
  var container = $(".sticky-container");
  var triggerTop = container.offset().top;
  var triggerBottom = triggerTop + container.height() - item.height();

  $(window).scroll(function() {
      var curentScroll = $(window).scrollTop();
      var isTop = curentScroll <= triggerTop;
      var isBottom = curentScroll >= triggerBottom;
      var relativeScroll = isTop ? triggerTop : isBottom ? triggerBottom: curentScroll;
      var offsetY = relativeScroll - triggerTop;

      item.css({
'-webkit-transform' : 'translateY(' + offsetY + 'px)',
        'transform' : 'translateY(' + offsetY + 'px)',
      });
  })
}
});

您的问题是,例如CSS上的chrome会始终舍入基于像素的值,换句话说,它将不会考虑小数像素,而是舍入或丢弃它们。 但是,在浏览器中尊重小数点百分比,因此不是Jquery导致了这种情况,而是CSS本身以解释规则的方式。

暂无
暂无

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

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