473,386 Members | 1,621 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,386 software developers and data experts.

Div Scroll on MouseOver

Hi,

I am using a menu inside a div tag. What i want to do is to add scroll buttons (up and down ) along side div which move the div up and down on mouse over.How can i achieve this?

It would be very nice of you if you can provide a link to the article or blog where solution is provided to my problem.

Thanks in advance,
Saad Alam
Apr 7 '08 #1
15 33611
pronerd
392 Expert 256MB
I am using a menu inside a div tag. What i want to do is to add scroll buttons (up and down ) along side div which move the div up and down on mouse over.
If that can be done it would likely have to be done with an iFrame instead of a div tag. As far as I know div tags do not use scroll bars. IFrame tags will have scroll bars any time their content is longer or wider than the the dimensions of the iFrame.

You would have to check the DOM references to see if there are any attributes you can set to modify the scroll position.
Apr 7 '08 #2
gits
5,390 Expert Mod 4TB
hi ...

you might play with the div's overflow style-property ... have a look at the following simple example ... that scrolls a div when moving the mouse over custom scroll-controls:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <script type="text/javascript">
  3.     var scrolling = null;
  4.  
  5.     function scroll_up() {
  6.         var d = document.getElementById('scroller');
  7.  
  8.         d.scrollTop = d.scrollTop - 5;
  9.  
  10.         scrolling = window.setTimeout(function() {
  11.             scroll_up();
  12.         }, 100);
  13.     }
  14.  
  15.     function scroll_down() {
  16.         var d = document.getElementById('scroller');
  17.  
  18.         d.scrollTop = d.scrollTop + 5;
  19.  
  20.         scrolling = window.setTimeout(function() {
  21.             scroll_down();
  22.         }, 100);
  23.     }
  24.  
  25.     function stop_scroll() {
  26.         window.clearTimeout(scrolling);
  27.     }
  28.     </script>
  29.     <body>
  30.         <div style="color:red;" onmouseover="scroll_up();" onmouseout="stop_scroll();"> scroll up </div>
  31.         <div id="scroller" style="width:100px; height:70px; overflow:hidden;">
  32.             Hi,
  33.  
  34.             I am using a menu inside a div tag.
  35.             What i want to do is to add scroll buttons
  36.             (up and down ) along side div which move
  37.             the div up and down on mouse over.
  38.             How can i achieve this?
  39.  
  40.             It would be very nice of you if you can
  41.             provide a link to the article or blog
  42.             where solution is provided to my problem.
  43.  
  44.             Thanks in advance,
  45.             Saad Alam
  46.         </div>
  47.         <div style="color:blue;" onmouseover="scroll_down();" onmouseout="stop_scroll();"> scroll down </div>
  48.     </body>
  49. </html>
  50.  
kind regards
Apr 7 '08 #3
hi ...

you might play with the div's overflow style-property ... have a look at the following simple example ... that scrolls a div when moving the mouse over custom scroll-controls:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <script type="text/javascript">
  3.     var scrolling = null;
  4.  
  5.     function scroll_up() {
  6.         var d = document.getElementById('scroller');
  7.  
  8.         d.scrollTop = d.scrollTop - 5;
  9.  
  10.         scrolling = window.setTimeout(function() {
  11.             scroll_up();
  12.         }, 100);
  13.     }
  14.  
  15.     function scroll_down() {
  16.         var d = document.getElementById('scroller');
  17.  
  18.         d.scrollTop = d.scrollTop + 5;
  19.  
  20.         scrolling = window.setTimeout(function() {
  21.             scroll_down();
  22.         }, 100);
  23.     }
  24.  
  25.     function stop_scroll() {
  26.         window.clearTimeout(scrolling);
  27.     }
  28.     </script>
  29.     <body>
  30.         <div style="color:red;" onmouseover="scroll_up();" onmouseout="stop_scroll();"> scroll up </div>
  31.         <div id="scroller" style="width:100px; height:70px; overflow:hidden;">
  32.             Hi,
  33.  
  34.             I am using a menu inside a div tag.
  35.             What i want to do is to add scroll buttons
  36.             (up and down ) along side div which move
  37.             the div up and down on mouse over.
  38.             How can i achieve this?
  39.  
  40.             It would be very nice of you if you can
  41.             provide a link to the article or blog
  42.             where solution is provided to my problem.
  43.  
  44.             Thanks in advance,
  45.             Saad Alam
  46.         </div>
  47.         <div style="color:blue;" onmouseover="scroll_down();" onmouseout="stop_scroll();"> scroll down </div>
  48.     </body>
  49. </html>
  50.  
kind regards
Thank you so much gits.
Apr 8 '08 #4
gits
5,390 Expert Mod 4TB
no problem ;) ... thats why this forum is here :) ... post back to the forum in case you have more questions ...

kind regards
Apr 8 '08 #5
Is there any way to be able to be aware of when the div content "bottom" has been reached so that I can hide the "DOWN" button, and same for top? Is there javascript that can tell when a certain element of the div (last line, a spacer image) is on the screen and then report this state back so I can then hide the "DOWN" button? THANKS!
May 29 '09 #6
acoder
16,027 Expert Mod 8TB
The top is easy: if it's 0, it's at the top. For the bottom, check that it's equal to the scrollHeight.
May 30 '09 #7
That makes sense. Thanks.

One thing (a big one!) -- I'm enough of a novice that I'm not sure what syntax I need to read the scrollHeight and have an IF statement (I'm guessing) to then change the element's display property. Anyone want to hook a self-taught novice up?

And while we're at it, the effect I'd really like to have is one without an explicit up and down "button" but instead for scrolling to work like this:

http://deluxe-menu.com/scrollable-submenus-sample.html
(hover over Samples I and you'll see it "smart scroll").

Any help is appreciated. Thanks.
May 30 '09 #8
acoder
16,027 Expert Mod 8TB
Add an ID to the 'link', e.g.
Expand|Select|Wrap|Line Numbers
  1. <div id="scrollup" style="color:red;" onmouseover="scroll_up();" onmouseout="stop_scroll();"> scroll up </div>
and then add a little snippet to the scroll_up() function:
Expand|Select|Wrap|Line Numbers
  1. if (d.scrollTop == 0) {
  2.     document.getElementById("scrollup").style.display = "none";
  3. else {
  4. ...
In scroll_down(), it'd be:
Expand|Select|Wrap|Line Numbers
  1. if (d.scrollTop == d.scrollHeight) {
  2.     document.getElementById("scrolldown").style.display = "none";
  3.  
Of course, you'd need to add code to display them again.

However, you mention that you want "smart" scrolling. For that you'd need to see the mouse position within the div. If it's below a certain point, start scrolling. Once it goes above that point, scroll back up.
May 31 '09 #9
@acoder
GREAT! I'm gonna try it. Mil Gracias.
Jun 1 '09 #10
edit: never mind! figured it out! crisis begets creativity :D

Hi, thank you for posting this code. I was able to implement it and get it to work. Is there a way to have more than one instance of this on a page? I have three separate divs with text in them on one page that I would like to have scroll like this.

I'm sorry if this is has an obvious answer, but I'm a javascript newbie. Thanks in advance for any help!

@gits
Sep 16 '09 #11
gits
5,390 Expert Mod 4TB
just adapt the scroll_up() and scroll_down() methods with a parameter that allows you to retrieve the corresponding 'instance' ... you might pass the id of the node and use it in the functions ... and don't forget to update the onmouseover-calls :)

kind regards
Sep 17 '09 #12
da1vid
1
Hello!

Very good joob, thanks a lot!

I have just one question. Is there any possibility that it would be possible to scroll content with mouse wheel?

THANKS A LOT AGAIN!
Sep 18 '10 #13
gits
5,390 Expert Mod 4TB
you might add a mousewheel listener ... you might have a look here for a start ...
Sep 22 '10 #14
Can this solution be easily adjusted to scroll left and right instead of up and down?
thanks
Feb 3 '12 #15
boop
1
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     var scrolling = null;
  3.  
  4.     function scroll_left() {
  5.         var d = document.getElementById('scroller');
  6.  
  7.         d.scrollLeft = d.scrollLeft - 5;
  8.  
  9.         scrolling = window.setTimeout(function() {
  10.             scroll_left();
  11.         }, 20);
  12.     }
  13.  
  14.     function scroll_right() {
  15.         var d = document.getElementById('scroller');
  16.  
  17.         d.scrollLeft = d.scrollLeft + 5;
  18.  
  19.         scrolling = window.setTimeout(function() {
  20.             scroll_right();
  21.         }, 20);
  22.     }
  23.  
  24.     function stop_scroll() {
  25.         window.clearTimeout(scrolling);
  26.     }
  27.     </script>
this worked for me!
Jun 6 '12 #16

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

Similar topics

1
by: Michael Hill | last post by:
I'm trying to implement a scrolling div. Here is a test page that was created: http://www.hulenbend.net/test2.html When I mouseover the down arrow I want to be able to move the div up showing...
14
by: J. Makela | last post by:
Hallo. This should be a pretty entertaining question for you *real* javascript writers.. I, being the lowly photoshop guy at an ad agency made the mistake of actually saying "HTML" in a...
2
by: Alex | last post by:
On my page I have a lot string like this: <span onmouseover="callMe(this)" onmouseout="callMe(null)" >abc1</span> <span onmouseover="callMe(this)" onmouseout="callMe(null)" >abc2</span> <span...
2
by: xleonard | last post by:
Hoping someone can help me figure out why some code I'm trying to learn isn't working. I found a javascript scroll effect that I really like on this page:...
3
by: Annette Acquaire | last post by:
I have and image map with a dozen hotspot links on it that I'm trying to get to open a new image over existing one on mouseover of each COORD. The only thing I was able to do was swap image on...
23
by: Schannah | last post by:
I'm trying to create a design which mimics the Radiohead website in the action on this page, but the problem is that they use PHP for the effect and I have no idea about PHP. I'm very amateur: fairly...
1
by: dave345 | last post by:
This javascript issue is in an app using C# / .Net 2.0 running on XP. First post, please mention if I mess up any conventions of this forum. I’ve got a mouseover event that only works properly...
2
by: Saad Alam | last post by:
Hi, I am using a menu inside a div tag. What i want to do is to add scroll buttons (up and down ) along side div which move the div up and down on mouse over.How can i achieve this? It would...
3
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.....
15
Claus Mygind
by: Claus Mygind | last post by:
I have a <div> tag in my app that I minimize on the screen thereby only showing the top line of the content in that division. The user activates the content (maximizes the content) with the...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.