C
C
Chokatillo2017-10-03 06:13:38
JavaScript
Chokatillo, 2017-10-03 06:13:38

Two scripts not working together?

I have two scripts side by side:

$(window).scroll(function(e){
  parallax();
});
function parallax(){
  var scrolled = $(window).scrollTop();
  $('#lk-conteyner').css('background-position-y',+(scrolled*0.5)+'px');
}




$(window).scroll(function(e){
  parallax();
});
function parallax(){
  var scrolled = $(window).scrollTop();
  $('.Robort_svg svg').css('top',-(scrolled*0.2)+'px');
}


Both create a parallax effect
Works, for some reason, only the second

What is the problem, how to fix it?
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2017-10-03
@serovpochta

your version is not at all gentlemanly: with each scroll event, a new event handler will be hung on window.

$(window).scroll(parallax);
var lkContainer = $('#lk-conteyner');
var robotSVG = $('.Robort_svg svg');
function parallax() {
  var scrolled = $(window).scrollTop();
  lkContainer.css('background-position-y',+(scrolled*0.5)+'px');
  robotSVG.css('top',-(scrolled*0.2)+'px');
}

study the theory, otherwise you will have to form-slap until the end of time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question