A
A
Alexander Karpov2016-12-06 11:34:13
css
Alexander Karpov, 2016-12-06 11:34:13

How to bypass background position change delay in browser?

I sketched out such a code, in the hope that it will be possible to implement parallax scrolling. but in all browsers the background twitches when scrolling. I would like to know if there is a way to keep this method but eliminate the lags?

$paralaxBlock = $('.order.order-position');
  var img = new Image;
  var href = $paralaxBlock.css('background-image').replace(/url\(\"|\"\)$/ig, "");
  img.src = href;
  img.onload = function(){
    $paralaxBlock.css('background-size','cover')
    $paralaxBlock.css('background-position-x','center')
    $paralaxBlock.css('background-position-y',(-1)*$paralaxBlock[0].getBoundingClientRect().top)
    var original = $paralaxBlock[0]
    setInterval(function() {
       $paralaxBlock.css('background-position-y',0-original.getBoundingClientRect().top)
    },0);
    
   // $(window).scroll(function(){
     // $paralaxBlock.css('background-position-y',(-1)*$paralaxBlock[0].getBoundingClientRect().top)
   // });
  }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question