Aaron Yodaiken
Aaron Yodaiken

Reputation: 19551

Fixed position in only one direction

So, essentially, I'd like to have an item that is fixed to the the bottom of the page, but when the view scrolls horizontally, it should horizontally scroll too.

I can hack out a means of doing this with JavaScript, but is there any CSS way to do it? I don't mind a few extra DIVs here and there.

Upvotes: 16

Views: 12636

Answers (2)

CSS part:

#footer {
    position:fixed;
    bottom:0px;
    left:0px
}

jQuery part:

$(window).scroll(function(){
    $('#footer').css('left','-'+$(window).scrollLeft()+'px');
});

Upvotes: 15

Giovanni
Giovanni

Reputation: 62

Really the jQuery part must be like:

var s = $(window).scrollLeft() - scroll_old;    
scroll_old = $(window).scrollLeft(); // initially = 0;
var diff = left_num - s;
var new_left = diff+"px";

then like above...

Upvotes: 2

Related Questions