mzubala / jquery-custom-scrollbar

189 stars 102 forks source link

MaxOverviewPosition #20

Closed tobias-r closed 10 years ago

tobias-r commented 10 years ago

Could you put

calculateMaxOverviewPosition:function(){ return Math.max(0,this.sizing.size(this.scrollable.$overview)-this.sizing.size(this.scrollable.$viewPort)) }

Otherwise it's not working for me!! Content moves to bottom, but i need it to stick to the top.

Think about it. I couldn't see any disadvantages, MaxOverviewPos should not be smaller than 0!

Thanks

mzubala commented 10 years ago

Max overview position is calculated like this:

calculateMaxOverviewPosition: function () { return this.sizing.size(this.scrollable.$overview) - this.sizing.size(this.scrollable.$viewPort); }

If it is < 0, it means that this.sizing.size(this.scrollable.$overview) < this.sizing.size(this.scrollable.$viewPort);

In such case the scrollbar shouldn't appear. I'm guessing that you resized your scrollable component perhaps by dynamically adding some stuff and forgot to call: $("your-element").customScrollbar("resize")

tobias-r commented 10 years ago

I am not quite sure, but I think the case is, that I need the content to be scrolled to bottom, unless, there is no scrollbar. Then it should stick to the top. So a list, which builts up from top, but if it's getting longer than the container (scroll added), then it should always scroll to bottom. I think for that I simply call scrollToY(100000).

Without my changes, even one line sticks to bottom, plus everytime i add a line and call resize, content moves again from top to bottom - a weird behaviour.

The 10 Characters will do only good ;-)

mzubala commented 10 years ago

You can pass an extra boolean keepPosition param to resize. If you call:

$("your-element").customScrollbar("resize", true)

it will leave the scrolled content in the same position.

tobias-r commented 10 years ago

Yes, I know, but I only want to keep the position, if the container does not require a scrollbar. After the resize command is supposed to scroll to bottom. And I don't see any other way to do this.

mzubala commented 10 years ago

If the container does not require a scrollbar then it doesn't matter if you pass keepPosition equal to true or false cause it will always show the whole content.

I think what we need to have is not a boolean param to resize but some enum position param that would say what to do after resize. You could pass: "top" and it would move the scrollbar top after resize, "bottom" would move the scrollbar to the bottom, "keep" would make it show the same content as before resize and "proportional" would keep the same scroll percent as before resize. Do you think that would help you?

tobias-r commented 10 years ago

Dunno, probably not. You see you got a div with lets say 500px height and you add line by line followed by scrollToBottom (or, cos you dont have it scrollToY(1000000).

Before the content reaches 500px it should be aligned top, after always the newest entry (bottom entry) has to be shown, so the container need to scroll from its current position to bottom.

Works with Math.max, else not

mzubala commented 10 years ago

Oh, ok I now get what your problem is. You call scrollToY before the scrollbar appears and content moves down which is a bug. I don't know if Math.max is a good fix for that but I'll definitely fix it.