Answer the question
In order to leave comments, you need to log in
How to change the code so that the object moves in a specific div and not across the entire page?
there is a code<div id='object'></div>
#object {
position: fixed;
left: 0;
top: 50%;
height: 30px;
width: 30px;
background: black;
}
body {
height: 3000px;
background: grey;
}
var window_width = $(window).width() - $('#object').width();
var document_height = $(document).height() - $(window).height();
$(function () {
$(window).scroll(function () {
var scroll_position = $(window).scrollTop();
var object_position_left = window_width * (scroll_position / document_height);
$('#object').css({
'left': object_position_left
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question