2

I want to use scoll images or div's when i was resize the window, but it actually does not work. the only the part of scoll is working when i write it seperately. Anyone here to help?

$(window).resize(function() { if ($(window).width() >= 767) { $(window).scroll(function() { $(".careers-philosophy__image").css({ "bottom": ($(window).scrollTop()/15) + "px" }); $(".careers-philosophy__image2").css({ "bottom": ($(window).scrollTop()/25) + "px" }); $(".carrer-block").css({ "bottom": ($(window).scrollTop()/10) + "px" }); $(".fast").css({ "bottom": ($(window).scrollTop()/5) + "px" }); }); } }); 

1 Answer 1

4

You shouldn't put $(window).scroll() in an event handler since itself is alos an event registration.

If you need the handler to be triggered on both resize and scroll, you can write it like this:

function handler(){ if ($(window).width() >= 767) { $(".careers-philosophy__image").css({ "bottom": ($(window).scrollTop() / 15) + "px" }); $(".careers-philosophy__image2").css({ "bottom": ($(window).scrollTop() / 25) + "px" }); $(".carrer-block").css({ "bottom": ($(window).scrollTop() / 10) + "px" }); $(".fast").css({ "bottom": ($(window).scrollTop() / 5) + "px" }); } } $(window).resize(handler); $(window).scroll(handler); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.