With JavaScript how can you detect that there is overflow in an element and make a custom element appear to enable scrolling inside that element?
-
I am creating a blog theme where the post that has a set height. The text in the <article> will be scrollable if there is enough text to exceed past the height of its parent. The current aesthetic problem is the ugly standard scroll that cannot be modified for Firefox or Internet Exploder. I will find a way to hide the standard scroll bar. But if (and only if) there is overflow, i want an element to appear at the bottom left of the article to scroll up or down or scroll to top. But that part does not matter what I want in that element. All I care about at this point is to: Detect overflow Show element if overflow
-
Answer:
If you use jQuery, you can try this: if ($('article')[0].scrollHeight > $('article')[0].innerHeight()) { //Text has over-flowed } And of course you can extract the same properties with plain JavaScript, with a little more work: document.getElementsByTagName("article")[0].scrollHeight
Marcello La Rocca at Quora Visit the source
Other answers
Well, in javascript you can always measure the difference between the offset height and the scroll height. var article = document.getElementsByTagName('article')[0]; if (article.scrollHeight > article.offsetHeight) { // article element has a scrollbar }
Mohab Samman
Related Q & A:
- How To Make A Custom Motorcycle?Best solution by Yahoo! Answers
- How can I detect changes in XML?Best solution by Stack Overflow
- How can I remove a casset tape from my car player? It is a 2003 Hyundai Sonota. Does anyone else this problem?Best solution by Yahoo! Answers
- How can I burn a .rmvb file onto a DVD for viewing on a regular DVD player?Best solution by Yahoo! Answers
- Can I make a custom Layout for my yahoo group?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.