开发者

hide lines of text not fully visible with javascript & css

I think this might be impossible, but is there some way using JQuery to prevent lines of text not fully visible from showing up on the screen when a user scrolls un开发者_运维百科til the entire line is visible? That is, we want to prevent something like this from showing up:

hide lines of text not fully visible with javascript & css

Thanks!


I agree with @rahmanisback, don´t mess with the user's browsing experience.

However, what would perhaps be a nice "inbetween" solution, is using a transparency gradient so that the bottom pixels fade out. But that would apply also to "whole" lines, so perhaps that´s not a good solution for your problem.


I don't know if there is something out there to do that. But I think it will cause confusion more that it would make any visual enhancement ever. A user will not be happy when scrolling down and finds lines just "popup" suddenly, in opposite to normally easing out as a result of scrolling action.

After all, when we speak about a scrollable HTML element with scrollbars visible, a user is aware text might be partially shown and that is normal and needs to be scrolled down to read the remaining. I really would not recommend that.

But for a technical answer, I think you would need to fix the CSS line-height property of that scrolling element, say make it 8px or whatever fits your layout. Then, capture the scroll event and devide the jQuery scrollTop() by that CSS line-height, then check the results: if it have a fraction then that means there is a "partially visible" line. Don't forget aout margin and padding that can cause mistakes when calculating.


I believe I have had this problem also, in that you have a div with a specific height and overflow hidden.

Thinking about it i would resize the div based on the line-height of the text in the div.

Change the height of div so that it equals a multiple of the line height of the containing text.... ie 3 lines of text with line-height = 16 change the div height from 50 to 48px.

( i posted this at the same time as rahmanisback' answer )


Hypothetically you could measure the height of text area, measure the height of the line, find scroll position do some math and then have some way of hiding text that is not fully exposed yet (eg Using a white div of x height depending on your math). However, it seems like a lot of trouble to go to for something that is usually a non-issue. You might also be able to do something with the overflow property, but you might have some issues with that I'm not sure.

I thought of an alternate method that would be easier to implement. Capture scroll events and then change it to the closest multiple of line height.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜