html scroll code example

Example 1: smooth scroll css

html {
  scroll-behavior: smooth;
}

/* No support in IE, or Safari
You can use this JS polyfill for those */
http://iamdustan.com/smoothscroll/

Example 2: css no overflow

div.ex1 {
  overflow: scroll;
}

div.ex2 {
  overflow: hidden;
}

div.ex3 {
  overflow: auto;
}

div.ex4 {
  overflow: visible;
}

Example 3: how to scroll

Selenium does not have a method for scrolling
 but there are some ways to scroll:
 
   #1 ->=moveToElement= coming from Actions class
   will scroll down and up to given web element
   #2 Using JSExecutor: We can inject JavaScript
   code in our Java+Selenium code using JSExecutor
   which helps us scroll up, down, left, right.
   We need to create instance of JS executor,
   then cast our driver type of it.
==================================================   
   
  syntax is =   
   JavaScriptExecutor js = (JavaScriptExecutor) Driver.getDriver();
   js.executeScript("in here we need to pass js code that scrolls");
    
 js.executeScript("window.scrollBy(0,250)");
 js.executeScript("arguments[0].scrollIntoView(true);", WebElement);

Example 4: scroll down style

<script type="text/javascript">
$window.scrollTop(function(){ 

var a = 112;
var pos = $window.scrollTop();
if(pos > a) {
    $("menu").css({
                position: 'fixed'
            });
}
else {
    $("menu").css({
                position: 'absolute',
                top:'600px'
            });
}
});
</script>

Tags:

Misc Example