Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
338 views
in Technique[技术] by (71.8m points)

jquery - POsition of image not changing with window scroll

I am using this code to slide the image down when window is scroled down but nothing is happenning

$('#left_img').css("top",$(window).scrollTop()+"px");




#left_img {
margin:0 0 0 -55px !important;
position:absolute;
top:5px !important;
}

Is it possible to find out how much is height of whole scroll window and then if image reaches certain height then it should stop sliding down

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to actually capture the event first.

$(window).scroll(function() { 
    $('#left_img').css("top", $(window).scrollTop()+"px");
});

I don't know much about scrolling and positioning, but if you're not capturing the event, that could be you're problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...