473,804 Members | 2,132 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HOW TO!? Javascript Scroll

164 New Member
Okay, So trust me I have googled, and searched this board before posting..

Maybe I dont know the correct searching phrase.

I want to be able to recreate a text area for news on my site, and I want it to have a scroll area that is sharp looking. I know very little javascript, and understand that I probably should, But I dont think this should be TOO difficult.

Anyways I have provided a site with an example of how I want it to work

http://www.miserysignals.net/main.php

On the left side where their news is. HOW on earth would I create something like this??

My searches came back with numerous amounts of auto scrolling text areas, which is cool, but not what I want.

Any help would be amazing, Thanks JS, and AJAX gurus!

PS. I am using Dreamweaver cs3 if that may help at all???
Nov 14 '07 #1
14 4100
Dasty
101 Recognized Expert New Member
I can not see any auto-scrolling areas. I can see just area that can be scrolled manually. In this case, you can use "DIV" dom element with fixed height and width, while overflow style property will be set to auto.

[HTML]<div style="width:10 0px; height:100px; overflow:auto;" >
<H1>You can put whatever you want here</H1><br>
And here ...<br>
And here ...<br>
All will be inside DIV (scrollable)<br >
</div>[/HTML]

But site you was refering to is made in Macromedia Flash not in JS.
Nov 14 '07 #2
mbatestblrock
164 New Member
I was really hoping to get the custom up and down and scroll bar part going.

I can do it by just making by the way you just said, but it gives me the plain ole' scroll bar.

I believe the only flash part of the site is the header. The news area was achieved using JS, if I am correct, if I disable flash in my browser the news still comes up.

I just cannot find anything on how to make this "Graphical scrollbar" on any of my searches..

Hoping for a miracle.

-myke


I can not see any auto-scrolling areas. I can see just area that can be scrolled manually. In this case, you can use "DIV" dom element with fixed height and width, while overflow style property will be set to auto.

[HTML]<div style="width:10 0px; height:100px; overflow:auto;" >
<H1>You can put whatever you want here</H1><br>
And here ...<br>
And here ...<br>
All will be inside DIV (scrollable)<br >
</div>[/HTML]

But site you was refering to is made in Macromedia Flash not in JS.
Nov 14 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
I believe the only flash part of the site is the header. The news area was achieved using JS, if I am correct, if I disable flash in my browser the news still comes up.

I just cannot find anything on how to make this "Graphical scrollbar" on any of my searches.
You're correct. The first step is to use Firebug and right-click Inspect Element. You'll see it's a span with an img tag inside.
Nov 14 '07 #4
mbatestblrock
164 New Member
You're correct. The first step is to use Firebug and right-click Inspect Element. You'll see it's a span with an img tag inside.
k, I got firebug, inspected it, I still cannot figure out how they did it! Just lost.
Nov 14 '07 #5
Markus
6,050 Recognized Expert Expert
The code used:
Expand|Select|Wrap|Line Numbers
  1. var upH = 18; // Height of up-arrow
  2. var upW = 18; // Width of up-arrow
  3. var downH = 18; // Height of down-arrow
  4. var downW = 18; // Width of down-arrow
  5. var dragH = 72; // Height of scrollbar
  6. var dragW = 52; // Width of scrollbar
  7. var scrollH = 438; // Height of scrollbar
  8. var speed = 8; // Scroll speed
  9.  
  10. // And now... go to the bottom of the page...
  11.  
  12. // Browser detection
  13. var dom = document.getElementById ? true:false;
  14. var nn4 = document.layers ? true:false;
  15. var ie4 = document.all ? true:false;
  16.  
  17. var mouseY; // Mouse Y position onclick
  18. var mouseX; // Mouse X position onclick
  19.  
  20. var clickUp = false; // If click on up-arrow
  21. var clickDown = false; // If click on down-arrow
  22. var clickDrag = false; // If click on scrollbar
  23. var clickAbove = false; // If click above scrollbar
  24. var clickBelow = false; // If click below scrollbar
  25.  
  26. var timer = setTimeout("",500); // Repeat variable
  27. var upL; // Up-arrow X
  28. var upT; // Up-arrow Y
  29. var downL; // Down-arrow X
  30. var downT; // Down-arrow Y
  31. var dragL; // Scrollbar X
  32. var dragT; // Scrollbar Y
  33. var rulerL; // Ruler X
  34. var rulerT; // Ruler Y
  35. var contentT; // Content layer Y;
  36. var contentH; // Content height
  37. var contentClipH; // Content clip height
  38. var scrollLength; // Number of pixels scrollbar should move
  39. var startY; // Keeps track of offset between mouse and span
  40.  
  41. // Mousedown
  42. function down(e){
  43.   if((document.layers && e.which!=1) || (document.all && event.button!=1)) return true; // Enables the right mousebutton
  44.   getMouse(e);
  45.   startY = (mouseY - dragT);
  46.  
  47.   // If click on up-arrow
  48.   if(mouseX >= upL && (mouseX <= (upL + upW)) && mouseY >= upT && (mouseY <= (upT + upH))){
  49.     clickUp = true;
  50.     return scrollUp();
  51.   }  
  52.   // Else if click on down-arrow
  53.   else if(mouseX >= downL && (mouseX <= (downL + downW)) && mouseY >= downT && (mouseY <= (downT + downH))){
  54.     clickDown = true;
  55.     return scrollDown();
  56.   }
  57.   // Else if click on scrollbar
  58.   else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= dragT && (mouseY <= (dragT + dragH))){
  59.     clickDrag = true;
  60.     return false;
  61.   }
  62.   else if(mouseX >= dragL && (mouseX <= (dragL + dragW)) && mouseY >= rulerT && (mouseY <= (rulerT + scrollH))){
  63.     // If click above drag
  64.     if(mouseY < dragT){
  65.       clickAbove = true;
  66.       clickUp = true;
  67.       return scrollUp();
  68.     }
  69.     // Else click below drag
  70.     else{
  71.       clickBelow = true;
  72.       clickDown = true;
  73.       return scrollDown();
  74.     }
  75.   }
  76.   // If no scrolling is to take place
  77.   else{
  78.     return true;
  79.   }
  80. }
  81.  
  82. // Drag function
  83. function move(e){
  84.   if(clickDrag && contentH > contentClipH){
  85.     getMouse(e);
  86.     dragT = (mouseY - startY);
  87.  
  88.     if(dragT < (rulerT))
  89.       dragT = rulerT;    
  90.     if(dragT > (rulerT + scrollH - dragH))
  91.       dragT = (rulerT + scrollH - dragH);
  92.  
  93.     contentT = ((dragT - rulerT)*(1/scrollLength));
  94.     contentT = eval('-' + contentT);
  95.  
  96.     moveTo();
  97.  
  98.     // So ie-pc doesn't select gifs
  99.     if(ie4)
  100.       return false;
  101.   }
  102. }
  103.  
  104.  
  105.  
  106. function up(){
  107.   clearTimeout(timer);
  108.   // Resetting variables
  109.   clickUp = false;
  110.   clickDown = false;
  111.   clickDrag = false;
  112.   clickAbove = false;
  113.   clickBelow = false;
  114.   return true;
  115. }
  116.  
  117. // Reads content layer top
  118. function getT(){
  119.   if(ie4)
  120.     contentT = document.all.content.style.pixelTop;
  121.   else if(nn4)
  122.     contentT = document.contentClip.document.content.top;
  123.   else if(dom)
  124.     contentT = parseInt(document.getElementById("content").style.top);
  125. }
  126.  
  127. // Reads mouse X and Y coordinates
  128. function getMouse(e){
  129.   if(ie4){
  130.     mouseY = event.clientY + document.body.scrollTop;
  131.     mouseX = event.clientX + document.body.scrollLeft;
  132.   }
  133.   else if(nn4 || dom){
  134.     mouseY = e.pageY;
  135.     mouseX = e.pageX;
  136.   }
  137. }
  138.  
  139. // Moves the layer
  140. function moveTo(){
  141.   if(ie4){
  142.     document.all.content.style.top = contentT;
  143.     document.all.ruler.style.top = dragT;
  144.     document.all.drag.style.top = dragT;
  145.   }
  146.   else if(nn4){
  147.     document.contentClip.document.content.top = contentT;
  148.     document.ruler.top = dragT;
  149.     document.drag.top = dragT;
  150.   }
  151.   else if(dom){
  152.     document.getElementById("content").style.top = contentT + "px";
  153.     document.getElementById("drag").style.top = dragT + "px";
  154.     document.getElementById("ruler").style.top = dragT + "px";
  155.   }
  156. }
  157.  
  158. // Scrolls up
  159. function scrollUp(){
  160.   getT();
  161.  
  162.   if(clickAbove){
  163.     if(dragT <= (mouseY-(dragH/2)))
  164.       return up();
  165.   }
  166.  
  167.   if(clickUp){
  168.     if(contentT < 0){    
  169.       dragT = dragT - (speed*scrollLength);
  170.  
  171.       if(dragT < (rulerT))
  172.         dragT = rulerT;
  173.  
  174.       contentT = contentT + speed;
  175.       if(contentT > 0)
  176.         contentT = 0;
  177.  
  178.       moveTo();
  179.       timer = setTimeout("scrollUp()",25);
  180.     }
  181.   }
  182.   return false;
  183. }
  184.  
  185. // Scrolls down
  186. function scrollDown(){
  187.   getT();
  188.  
  189.   if(clickBelow){
  190.     if(dragT >= (mouseY-(dragH/2)))
  191.       return up();
  192.   }
  193.  
  194.   if(clickDown){
  195.     if(contentT > -(contentH - contentClipH)){      
  196.       dragT = dragT + (speed*scrollLength);
  197.       if(dragT > (rulerT + scrollH - dragH))
  198.         dragT = (rulerT + scrollH - dragH);
  199.  
  200.       contentT = contentT - speed;
  201.       if(contentT < -(contentH - contentClipH))
  202.         contentT = -(contentH - contentClipH);
  203.  
  204.       moveTo();
  205.       timer = setTimeout("scrollDown()",25);
  206.     }
  207.   }
  208.   return false;
  209. }
  210.  
  211. // reloads page to position the layers again
  212. function reloadPage(){
  213.   location.reload();
  214. }
  215.  
  216. // Preload
  217. function eventLoader(){
  218.   if(ie4){
  219.     // Up-arrow X and Y variables
  220.     upL = document.all.up.style.pixelLeft;
  221.     upT = document.all.up.style.pixelTop;    
  222.     // Down-arrow X and Y variables
  223.     downL = document.all.down.style.pixelLeft;
  224.     downT = document.all.down.style.pixelTop;
  225.     // Scrollbar X and Y variables
  226.     dragL = document.all.drag.style.pixelLeft;
  227.     dragT = document.all.drag.style.pixelTop;    
  228.     // Ruler Y variable
  229.     rulerT = document.all.ruler.style.pixelTop;    
  230.     // Height of content layer and clip layer
  231.     contentH = parseInt(document.all.content.scrollHeight);
  232.     contentClipH = parseInt(document.all.contentClip.style.height);
  233.   }
  234.   else if(nn4){
  235.     // Up-arrow X and Y variables
  236.     upL = document.up.left;
  237.     upT = document.up.top;    
  238.     // Down-arrow X and Y variables
  239.     downL = document.down.left;
  240.     downT = document.down.top;    
  241.     // Scrollbar X and Y variables
  242.     dragL = document.drag.left;
  243.     dragT = document.drag.top;    
  244.     // Ruler Y variable
  245.     rulerT = document.ruler.top;
  246.     // Height of content layer and clip layer
  247.     contentH = document.contentClip.document.content.clip.bottom;
  248.     contentClipH = document.contentClip.clip.bottom;
  249.   }
  250.   else if(dom){
  251.     // Up-arrow X and Y variables
  252.     upL = parseInt(document.getElementById("up").style.left);
  253.     upT = parseInt(document.getElementById("up").style.top);
  254.     // Down-arrow X and Y variables
  255.     downL = parseInt(document.getElementById("down").style.left);
  256.     downT = parseInt(document.getElementById("down").style.top);
  257.     // Scrollbar X and Y variables
  258.     dragL = parseInt(document.getElementById("drag").style.left);
  259.     dragT = parseInt(document.getElementById("drag").style.top);
  260.     // Ruler Y variable
  261.     rulerT = parseInt(document.getElementById("ruler").style.top);
  262.     // Height of content layer and clip layer
  263.     contentH = parseInt(document.getElementById("content").offsetHeight);
  264.     contentClipH = parseInt(document.getElementById("contentClip").offsetHeight);
  265.     document.getElementById("content").style.top = 0 + "px";
  266.  
  267.   }
  268.   // Number of pixels scrollbar should move
  269.   scrollLength = ((scrollH-dragH)/(contentH-contentClipH));
  270.   // Initializes event capturing
  271.   if(nn4){
  272.     document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP);
  273.     window.onresize = reloadPage;
  274.   }
  275.   document.onmousedown = down;
  276.   document.onmousemove = move;
  277.   document.onmouseup = up;
  278. }
  279. // Pop Up
  280. function openNewWindow(URLtoOpen, windowName, windowFeatures) { newWindow=window.open(URLtoOpen, windowName, windowFeatures); }
  281. // -->
  282.  
No idea what's going on there, looks long winded.

Haha, sorry for the lack of help.
Nov 14 '07 #6
mbatestblrock
164 New Member
Haha, thanks!

Man I didnt think something SO little could be so complicated, I have no idea what to do. Ill update if anything comes of it though.

Still open for suggestions.
Nov 14 '07 #7
acoder
16,027 Recognized Expert Moderator MVP
With the plain ole' scrollbar, it's easy. If you want a "graphical" scrollbar, you're going to have to work for it!

It's not as complicated as you think. If you don't need to support IE4 and Netscape 4 (old and ancient browsers), you could cut out a lot of the code.

Don't forget that with the JavaScript, you will also need the HTML and CSS.
Nov 14 '07 #8
mbatestblrock
164 New Member
Thanks a ton. Well see how it goes...
Nov 14 '07 #9
Markus
6,050 Recognized Expert Expert
Thanks a ton. Well see how it goes...
Wish you all the best :)

and let us know how you get along!
Nov 14 '07 #10

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

Similar topics

13
9467
by: Kai Grossjohann | last post by:
It seems that Ctrl-N in Mozilla opens a new empty browser window. That's fine, I don't need to do anything about it. But Ctrl-N in IE appears to clone the current window. Is there a way to intercept the key so that I can do stuff on the server side to make the new window behave correctly? (We have a JSP-based webapp which stores state in the session. Now if two windows access (and modify!) the same session, then madness will result....
4
9669
by: D Newsham | last post by:
Hi, This javascript creates a table that has a header and side column that do not move while scrolling through the table. I need to convert this to vb script. Can anybody help, or do you have code in vb (asp) that would do the same thing? <html> <head> <title>Scrolling Grid Demo</title>
14
12661
by: Karin Jensen | last post by:
Hi - I am trying to use Javascript to put material inside a table (i.e. alongside the previous material) if the user's screensize is big enough and outide the table (beneath table) if it isn't. The following code (tag properties and other extraneous material removed) works in IE but not Firefox: <table> <tr><td> first set of material </td>
1
1118
by: Bernie V | last post by:
Hi group, I use some javascript on my page to scroll some text. This is my situatiion: 1 aspx file : home.aspx with the main layout in the layout i use custom controls (ascx files) to show the whole page with the main layout of home.aspx. In the <head></head> tag of the home.aspx file I placed:
4
2284
by: Peter Bons | last post by:
Hi all, I have an asp.net page with a button that has a javascript onclick method attached to it to display a modal dialog like this: If reportHasParameters Then 'add client side onclick() event handler to display the popup dialog for entering parametervalues btnChangeParameters.Attributes.Add("onclick", String.Format("window.showModalDialog
0
984
by: rodchar | last post by:
hey all, am i running the following javascript as fast as possible: All i'm trying to do is move an innerDIV via an outerDIV left and right. if i click real fast on the button it only moves one step after 2 clicks, if i click real slow it will move normal. <script type="text/javascript"> var x // Gets innerDiv var y // Gets outerDiv var z; // Testing: Gets Label for testing purposes only
1
3820
by: Raffi | last post by:
Hi, I have an application screen with a CSS scroll area. Users click links in the scroll area which open small popup windows to enter data. When the data is submitted, the popup reloads the opener to update the page and closes itself. However when the parent page is updated, the div scrolls back to the top. Is there a way to have CSS remember the vertical scroll position and go back to it when the page is reloaded? Similar to...
9
4040
by: mevryck | last post by:
Greetings I have a huge Javascript with inclusion of external scripts and all. I got this by doing a XSLT . Now I have the contents in a Javascript variable, but I'm not able to update the element with the javascript contents. But when viewed as a seperate HTML file with the below contents I'm able to see the milonic menu http://www.milonic.com . <div>
1
3173
by: John L. | last post by:
How do I invoke the scroll() method of a window object for a scrollable IFRAME element in an HTML document? I am using IE 7.0, and I thought the following would work: document.frame01.scroll(x,y) or possibly document.getElementById('frame01').scroll(x,y)
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5675
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.