Endless Tutorial - jQuery - scrollTop( val ) method function

The scrollTop(val) method is used to set the scroll top offset to the passed value on all matching elements.

scrollTop( val ) - syntax

selector.scrollTop( val )

Here is the description of all parameters used by this method −

  • val - A positive number representing the desired scroll top offset.

scrollTop( val ) - example

Following is a simple example that simply illustrates the usage of this method −

<html>
   <head>
      <title>The jQuery Example</title>
      <script type="text/javascript" 
         src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
		
      <script type="text/javascript" language="javascript">
         $(document).ready(function(){
   
   
            $("div.demo").scrollTop(300);
         });
      </script>
		
      <style>
         div.demo {
   
   background:#CCCCCC none repeat scroll 0 0; border:3px 
            solid #666666; margin:5px; padding:5px; position:relative;
            width:200px; height:100px; overflow:auto;}
         p {
   
    margin:10px; padding:5px; border:2px solid #666; 
            width:1000px; height:1000px;}
      </style>
   </head>
	
   <body>
      <div class="demo"><p>Hello</p></div>
   </body>
</html>

This will produce the following output -

The scrollTop(val) method function in jQuery - Wuya Tutorial Network Wuya Tutorial Network provides the scrollTop(val) method to set the scroll top offset to the passed value on all matching elements. scrollTop(... https://www.learnfk.com/jquery/css-scrolltop-val.html

Guess you like

Origin blog.csdn.net/w116858389/article/details/132034751