By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,948 Members | 1,595 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,948 IT Pros & Developers. It's quick & easy.

scrollTo only if horizontal scrollbar

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.