John
John

Reputation:

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

Upvotes: 0

Views: 714

Answers (3)

Joberror
Joberror

Reputation: 5890

Make it a little bit neater;

$(window).scroll(function(){
       var getbodyt = $(window).scrollTop();
       var getbodyl = $(window).scrollLeft();
       $("#left_img").css({top: getbodyt, left: getbodyl});
    });

Upvotes: 0

Nasser Hadjloo
Nasser Hadjloo

Reputation: 12610

I think your javascript doesn't make sense! Why Do you scrolling Image (with javascript/jquery)?

All you need is to set

#imageID
{
    position: fixed;
    left: 20px;
    top: 20px;
}

It will scroll with page. So whats the reason to scrollimage with script?

Upvotes: 2

bschaeffer
bschaeffer

Reputation: 2904

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.

Upvotes: 2

Related Questions