2

I have two columns on my page.

The left column is one long list, the right is smaller.

When I scroll up and down I want the right column to float with the page not be static.

I've managed to get this working using this css:

    .connected {
        min-height:100px;
        float: left;
        width: 200px;
    }
    .connected.right {
        position: fixed; 
        min-height:100px;
        height: auto;
        float: right;
    }

and can be seen here on this FIDDLE.

The issue I have is if the right column is long, then it doesn't move at all and the bottom entries aren't accessible.

Is there any way to get the right column to scroll but only until you reach the end of it, then it is fixed untill you start scrolling back up ?

Thanks

1
  • There are 3 options. 1) Use Javascript for it. 2) Set a overflow so a Scrollbar will appear. 3) Make it smaller, like smaller font-size or less items. Commented Jun 8, 2015 at 10:33

2 Answers 2

1

What about setting overflow: auto; to the right column?

.connected.right {
    position: fixed;
    overflow: auto;
    min-height:100px;
    height: 200px;
    float: right;
}

This will set a scroll to it and will allow scrolling until the very end of the column.

Demo: https://jsfiddle.net/8fxosb5f/2/

Or you can remove the window scroll by setting overflow: auto to both columns. But that way you need to set a certain height of those columns. The result might not be what you need, still here's a demo:

https://jsfiddle.net/8fxosb5f/3/

Here's a really rough code, but I think you will manage to set it to fit your needs: (it requires jQuery)

var columnHeight = $('.right').outerHeight(true);

var windowHeight = $(window).height();
$(window).scroll(function () {

    if ($(this).scrollTop() + windowHeight >= columnHeight) {
        $('.right').css({
            position: 'fixed',
            top: -(columnHeight - windowHeight)
        });
    } else {
        $('.right').css({
            position: 'static',
            top: 'auto'
        });
    }
});

Demo: https://jsfiddle.net/8fxosb5f/5/

9
  • Thanks the first example is nearly what I'm trying to do.. I was hoping to have both columns scroll down and the the right fix when it got to the bottom..
    – Tom
    Commented Jun 8, 2015 at 10:33
  • I'm sorry, but I do not understand what you actually want. Can you post a picture or something? I'm guessing you are going to need javascript to do this, but still a simple "drawing" would be nice Commented Jun 8, 2015 at 10:36
  • Not sure how I can draw this. Currently both columns are longer than the page. As you scroll down the page, you also scroll down the columns. When you get to the bottom of the right column I'd like it to stop and the left to continue scrolling down.
    – Tom
    Commented Jun 8, 2015 at 11:00
  • But you want when the right columns content ends, the column to continue scrolling (something like position: fixed) as it's scrolled to the end? Commented Jun 8, 2015 at 11:03
  • 1
    Yep, just set the float to left on the right column: jsfiddle.net/8fxosb5f/6 Commented Jun 8, 2015 at 13:51
0

You wrote the css is incorrect

.connected.right {
        position: fixed; 
        min-height:100px;
        height: auto;
        float: right;
    }

change it to

.connected .right {
        position: fixed; 
        min-height:100px;
        height: auto;
        float: right;
    }

working example here

2
  • It's working like intended, but he want to make the right div dynamic until you reach the last entry, than be fixed and if you scroll up, it's dynamic again. Commented Jun 8, 2015 at 10:31
  • Thanks - but that doesn't fix the issue
    – Tom
    Commented Jun 8, 2015 at 10:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.