469,571 Members | 1,701 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,571 developers. It's quick & easy.

scrollTo only if horizontal scrollbar

How to tell if a horizontal scrollbar is present? I only want to use
scrollTo if horizontal scrollbar is present.

window.scrollbars.visibility doesn't specify which scrollbar is
present, so it gives a false result if there is vertical scrollbar but
not horizontal scrollbar.

TIA,
Anna
Jul 23 '05 #1
4 3557
anna wrote:
How to tell if a horizontal scrollbar is present? I only want to use
scrollTo if horizontal scrollbar is present.
window.scrollbars.visibility doesn't specify which scrollbar is
present, so it gives a false result if there is vertical scrollbar but
not horizontal scrollbar.
TIA,
Anna


You could give this a try, check for scrollWidth > clientWidth.
It works for my IE6, Netscape 7.1, Firefox 0.8.

function showscrollfeatures() {
var msg = 'clientHeight ' + window.document.body.clientHeight + '\n';
msg += 'clientWidth ' + window.document.body.clientWidth + '\n';
msg += 'offsetHeight ' + window.document.body.offsetHeight + '\n';
msg += 'offsetWidth ' + window.document.body.offsetWidth + '\n';
msg += 'scrollHeight ' + window.document.body.scrollHeight + '\n';
msg += 'scrollWidth ' + window.document.body.scrollWidth + '\n';
msg += 'scrollLeft ' + window.document.body.scrollLeft + '\n';
msg += 'scrollTop ' + window.document.body.scrollTop + '\n';
alert(msg);
}

function scrollbarcheck() {
var scrolling;
if ((window.document.body.scrollHeight >
window.document.body.clientHeight) ||
(window.document.body.scrollWidth >
window.document.body.clientWidth))
scrolling='true';
else
scrolling='false';
alert('scrolling='+scrolling);
}

Mike

Jul 23 '05 #2
mscir wrote:

Sorry, that should have been:

function showscrollfeatures() {
var wdb = window.document.body;
var msg;
msg += 'clientHeight ' + wdb.clientHeight + '\n';
msg += 'clientWidth ' + wdb.clientWidth + '\n';
msg += 'offsetHeight ' + wdb.offsetHeight + '\n';
msg += 'offsetWidth ' + wdb.offsetWidth + '\n';
msg += 'scrollHeight ' + wdb.scrollHeight + '\n';
msg += 'scrollWidth ' + wdb.scrollWidth + '\n';
msg += 'scrollLeft ' + wdb.scrollLeft + '\n';
msg += 'scrollTop ' + wdb.scrollTop + '\n';
alert(msg);
}

function scrollbarcheck() {
var wdb = window.document.body;
var scrolling;
if ((wdb.scrollHeight > wdb.clientHeight) ||
(wdb.scrollWidth > wdb.clientWidth))
alert('Scrolling=True');
else
alert('Scrolling=False');
}

Jul 23 '05 #3
FOLLOWUP
if (navigator.appName.indexOf("Netscape") != -1 &&
parseFloat(navigator.appVersion) < 5 ) {
if (document.width > window.innerWidth) {
document.write('<a
href="javascript:window.scrollTo(1000,window.pageY Offset)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
}
} else {
if (document.body.scrollWidth > document.body.clientWidth) {
document.write('<a
href="javascript:window.scrollTo(1000,document.bod y.scrollTop)"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"><img
src="/icons/redarrow.gif" border=0 alt="Scroll right"></a>');
}
}
Jul 23 '05 #4
anna wrote:
[nonsense again]


See <news:40**************@PointedEars.de>
PointedEars
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Pal Csepregi | last post: by
1 post views Thread by Marco Liedekerken | last post: by
1 post views Thread by dhnriverside | last post: by
4 posts views Thread by Sakharam Phapale | last post: by
2 posts views Thread by musicmouse | last post: by
14 posts views Thread by Michael Weis | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.