admin管理员组

文章数量:1305066

In my below code a function to scroll DIV for every set of intervals where when I try to scroll up due to interval refresh scroll bar again ing down.

My code:

   var int = self.setInterval("f2()", 1000);
   function f2() {
   var objDiv = document.getElementById("messages2");
   objDiv.scrollTop = objDiv.scrollHeight;
   }

Now, by using onscroll property for DIV is there anyway to stop scrolling down when holding scroll bar with mouse?

Something like

       var int = self.setInterval("f2()", 1000);
       function f2() {
       var objDiv = document.getElementById("messages2");
       // if(objDiv.onscroll) i.e. when the particular DIV's scroll bar is on hold by cursor.
          {
          return false;
          }
       else
          {
            objDiv.scrollTop = objDiv.scrollHeight;
          }
      }

If the above kind of function can be implemented anybody please correct its syntax. I am a newbie to JavaScript.

Thanks in advance..!

In my below code a function to scroll DIV for every set of intervals where when I try to scroll up due to interval refresh scroll bar again ing down.

My code:

   var int = self.setInterval("f2()", 1000);
   function f2() {
   var objDiv = document.getElementById("messages2");
   objDiv.scrollTop = objDiv.scrollHeight;
   }

Now, by using onscroll property for DIV is there anyway to stop scrolling down when holding scroll bar with mouse?

Something like

       var int = self.setInterval("f2()", 1000);
       function f2() {
       var objDiv = document.getElementById("messages2");
       // if(objDiv.onscroll) i.e. when the particular DIV's scroll bar is on hold by cursor.
          {
          return false;
          }
       else
          {
            objDiv.scrollTop = objDiv.scrollHeight;
          }
      }

If the above kind of function can be implemented anybody please correct its syntax. I am a newbie to JavaScript.

Thanks in advance..!

Share Improve this question edited Dec 27, 2011 at 18:16 Michael A 9,93022 gold badges72 silver badges117 bronze badges asked Dec 27, 2011 at 18:10 Mad coder.Mad coder. 2,1759 gold badges38 silver badges53 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

I’m not sure what you are asking here, but window has a scroll event that you can listen to, and so does any other element that has overflow: auto|scroll set using CSS.

You can’t prevent the default scrolling behavior, but you can use the scrollTo() method or the scrollTop property if you want to do something annoying like:

window.onscroll = function() {
    window.scrollTo(0,0);
};

Here is a nice pat table of the scroll event: http://www.quirksmode/dom/events/scroll.html

scrollTo() docs: https://developer.mozilla/en/Window.scrollTo

本文标签: scrollbarIs there any way to control scroll bar using JavaScriptStack Overflow