更新时间:2022-10-29 17:31:50
使用jQuery可以比较文档高度,scrollTop位置和视口高度,这可能会让您得到所需的答案。
以下行:
$(window).scroll(function(){
if(isMyStuffScrolling()){
//这里有一个滚动条!
}
});
函数isMyStuffScrolling(){
var docHeight = $(document).height();
var scroll = $(window).height()+ $(window).scrollTop();
return(docHeight == scroll);
}
How can I detect a Scrollbar presence ( using Javascript ) in HTML iFrame ?
I have already tried :
var vHeight = 0;
if (document.all) {
if (document.documentElement) {
vHeight = document.documentElement.clientHeight;
} else {
vHeight = document.body.clientHeight
}
} else {
vHeight = window.innerHeight;
}
if (document.body.offsetHeight > vHeight) {
//when theres a scrollbar
}else{
//when theres not a scrollbar
}
And I also had tried :
this.scrollLeft=1;
if (this.scrollLeft>0) {
//when theres a scrollbar
this.scrollLeft=0;
}else{
//when theres not a scrollbar
return false;
}
With no success..
I have searched the javascript objets on DOM Inspector, but didn't find anything.
Is is possible to detect a scrollbar presence in a iframe in javacscript ?
The iframe content comes from the same domain.
No success until now..
alt text http://www.upvtp.com.br/file.php/1/help_key.jpg
Using jQuery you can compare the document height, the scrollTop position and the viewport height, which might get you the answer you require.
Something along the lines of:
$(window).scroll(function(){
if(isMyStuffScrolling()){
//There is a scroll bar here!
}
});
function isMyStuffScrolling() {
var docHeight = $(document).height();
var scroll = $(window).height() + $(window).scrollTop();
return (docHeight == scroll);
}