Monday, 21 May 2012

Vertical scrolling in div


Find simple code here to do vertical smooth scrolling in div

<
script type="text/javascript">
        var InterVal;
        var divScroll;
        function ScrollUp(obj) {
            divScroll = document.getElementById(obj);
            InterVal = setInterval(StartUp, 50);

        }
     
       function ScrollDown(obj) {
            divScroll = document.getElementById(obj);
            InterVal = setInterval(StartDown, 50);
        }

        function StartUp() {
            divScroll.scrollTop -= 2;
        }

        function StartDown() {
            divScroll.scrollTop += 2;
        }

        function Stop(obj) {
            clearInterval(InterVal);
        }

        function Hide(DivMid, divup, divdown) {
            var divUp = document.getElementById(divup);
            var divDown = document.getElementById(divdown);
            DivMid.scrollTop >= 6 ? divUp.style.display = "block" :
                                                divUp.style.display = "none";
            DivMid.scrollHeight <= DivMid.clientHeight + DivMid.scrollTop ?
                                                        divDown.style.display = "none" :
                                                        divDown.style.display = "block";
        }      
    </script>


<div id="up" align="center" onmouseover="return ScrollUp('divScroll')"
        onmouseout="return  Stop('divScroll')"  style="width: 30%;
        
background-color: #FFDEAD; display: none;"> UP</div>

 <div style="width: 30%; height: 100px; overflow: hidden;" id="divScroll"
         onscroll="Hide(this,'up','down');">
            Ajay <br />
            Patel <br />
            Patel <br />
            Ajay  <br />
            Rahul <br />
            Me    <br />
            Sam  <br />
            Pizza <br />
            Hut   <br />
            Like   <br />
            Ajay  <br />
            Rahul <br />
            Me    <br />
        </div>

        <div id="down" align="center" onmouseover="return ScrollDown('divScroll');"
               onmouseout="return Stop('divScroll');" style="width: 30%;
               background-color: #FFDEAD;">down</div>

 
         Result will like this :



Enjoy....................

1 comment:

  1. WHAT CHANGES I NEED TO DO IF I WANT TO IMPLEMENT SAME FOR HORIZONTAL THAT IS RIGHT TO LEFT INSTEAD UP TO DOWN? PLZ HELP

    ReplyDelete