473,378 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

DHTML Scrollbar not working in FF

I found code close to this somewhere yesterday for a vertical scrollbar and I modified it for a horizontal scroll bar. It seems to work in IE 7 and Netscape 7, but it isn't working for the FF I have 1.5 and 2.0. It is not getting the correct docW which is the full document size. Any suggestions are more than welcome. Thanks.

<style type="text/css">

#container {
position : absolute;
top : 10px;
left : 10px;
width : 100%;
height : 120px;
overflow : hidden;
}

#content {
position : relative;
}

p {
font : normal 10px/14px arial,helevetica,san-serif;
}

#scrollArea {
position : absolute;
left : 0px;
top : 130px;
height : 10px;
width : 100%;
border : 1px solid #666;
overflow : hidden;
}

#scroller {
position : absolute;
top : -1px;
width : 10px;
height : 10px;
background : #AAA;
border-top : 1px solid #666;
border-bottom : 1px solid #666;
}

</style>
<script type="text/javascript" src="dom-drag.js"></script>
</head>

<body bgcolor="#464646" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

<script type="text/javascript">

//We wrap all the code in an object so that it doesn't interfere with any other code
var scroller = {
init: function() {

//collect the variables
scroller.docW = document.getElementById("content").offsetWidth;
scroller.contW = document.getElementById("container").offsetWidth;
scroller.scrollAreaW = document.getElementById("scrollArea").offsetWidth;

//alert(scroller.docW+" "+scroller.contW+" "+scroller.scrollAreaW);

//calculate Width of scroller and resize the scroller div
//(however, we make sure that it isn't to small for long pages)
scroller.scrollW = (scroller.contW * scroller.scrollAreaW) / scroller.docW;
if(scroller.scrollW < 15) scroller.scrollW = 15;
document.getElementById("scroller").style.width = Math.round(scroller.scrollW) + "px";

//what is the effective scroll distance once the scoller's Width has been taken into account
scroller.scrollDist = Math.round(scroller.scrollAreaW-scroller.scrollW);

//make the scroller div draggable
Drag.init(document.getElementById("scroller"),null ,-1,scroller.scrollDist,0,0);

//add ondrag function
document.getElementById("scroller").onDrag = function (x,y) {
var scrollX = parseInt(document.getElementById("scroller").style .left);
var docX = 0 - (scrollX * (scroller.docW - scroller.contW) / scroller.scrollDist);
document.getElementById("content").style.left = docX + "px";
}
}
}

onload = scroller.init;
</script>

<div id="container">
<div id="content">
<?= $thumbText ?>
</div>
</div>

<div id="scrollArea">
<div id="scroller"></div>
</div>
May 2 '07 #1
10 2726
drhowarddrfine
7,435 Expert 4TB
I'm not a javscript guy and didn't look too hard but try and set html and body to 100% width in the css and see if that solves it.

html,body{
width:100%
}
May 2 '07 #2
I did not see any change. Sorry.
May 2 '07 #3
acoder
16,027 Expert Mod 8TB
See this link. Firefox counts only the actual content in offsetWidth as per the spec. while IE counts the padding and border too.
May 2 '07 #4
drhowarddrfine
7,435 Expert 4TB
I almost mentioned something like that link but I hesitate to comment about such things here. IE is using its broken box model while FF is working correctly.
May 2 '07 #5
I am still not getting it. All the attributes I use to find the full document width only comes up with what is seen inside the div container as the total document in FF. In IE and Netscape 7 it gives me a number which is the total document width, which is then compared to how much screen area there is and then it creates the scroll bar at the same proportions as that. In FF, the total document size is giving me pretty much the same number as the viewable size, therefore the ratio is not correct and thus making the scrollbar the correct size.

Test example

Any help is appreciated. If it has already been explained and I just don't get it, I am sorry. Please hold my hand if you don't mind. Thanks.
May 2 '07 #6
drhowarddrfine
7,435 Expert 4TB
Again, I'm hesitant to post suggestions here but you absolutely position some of the divs. Absolutely positioned elements are removed from the normal flow and will collapse in FF, as they should. IE has bugs involved with this so I'm wondering if taking the absolute positioning out and testing that way makes a difference.
May 2 '07 #7
acoder
16,027 Expert Mod 8TB
See this link which gives a comparison of the different viewport properties in different browsers.

Hope that helps.
May 3 '07 #8
I don't think I am explaining my self very well. I believe FF is returning all variables as they should I guess. But they are not helping me achieve what I want.

There is content that is inside a div and then another div containing that first div. The script is supposed to figure out how wide this content is, and then figure out how wide the container div is and figure out the ratio of the 2 so the scrollbar can be built in the same proportions.

Problem is that the script is giving me a content width that is the same as the container width and therefore producing a scrollbar that spans the entire width of the container width.

Does this make sense? Thanks.
May 3 '07 #9
I finally figured it out. It was that the content width was set to 100%. I made it an actual pixel width and it worked. Thanks for all the help though.
May 3 '07 #10
acoder
16,027 Expert Mod 8TB
Glad you got it working. Sometimes it's the little things which work.
May 3 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Barbara de Zoete | last post by:
On one of my pages http://home.wanadoo.nl/b.de.zoete/html/tekeningen.html I have a div containing thumbnails (who ever came up with that word?) to select a larger view of a picture. The div is...
3
by: buht | last post by:
Hello Everyone, Fairly new to c# here and have a question regarding scrollbars, particularly a vertical scrollbar. It looks like my options are restricted for the textbox scrollbars being...
22
by: Colin McGuire | last post by:
I apologize for posting yet another scrollbar question. Here is my code. All I want is for a diagonal line to appear from coordinates (0,0) to (width,height) in a usercontrol regardless of whether...
8
by: Dustan | last post by:
I'm trying to get a scrollbar bound with a Frame, and I keep on getting a scrollbar, but it doesn't actually scroll. Some help, please?
10
by: cjparis | last post by:
Hello everyone. If anyone can give me a hand I would be gratefull Am doing a site which requires a moving element and have used DHTML to do it. Have a simple Browser detect script to sort IE...
3
by: nicky77 | last post by:
Hi, before you say it i know frames are bad practice - but i'm developing dynamic content on a site which has already been designed, so alas there's no option but to use them. Anyway, I just want to...
3
by: Nebulism | last post by:
Hi everyone, I am working on a module for my GUI that shows one image with an index value below and would use a scrollbar to control which of the images are displayed. The images are stored in a...
3
by: neovantage | last post by:
Hey All, I want to create 3d Scrollbar using javascript/dhtml in my static pages. My 3d scrollbar feel n look you can see from the attached image. I hope to have a solution from this great...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.