目录

Implementing Content Scrolling

A web page can scroll only when its content height or width exceeds the visible area. Web page scrolling can be performed in several ways, including using external devices, calling ArkTS side interfaces, and calling JS side interfaces.

Using External Devices

You can control web page scrolling through the touchscreen, touchpad, and mouse wheel in the following ways.

Calling ArkTS APIs

Calling JS APIs

Scrolling to the Top by Tapping the Status Bar

When the web page is not at the top or is being flung downward, you can use the backToTop method to return to the top of the web page. After it is enabled, tapping the status bar interrupts the fling and scrolls the web page to the top.

The loaded HTML file:

<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" id="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        .blue {
          background-color: lightblue;
        }
        .green {
          background-color: lightgreen;
        }
        .blue, .green {
         font-size:16px;
         height:200px;
         text-align: center;       /* Horizontally centered */
         line-height: 200px;       /* Vertically centered (the height matches the container height) */
        }
    </style>
</head>
<body>
<div class="blue" >webArea</div>
<div class="green">webArea</div>
<div class="blue">webArea</div>
<div class="green">webArea</div>
<div class="blue">webArea</div>
<div class="green">webArea</div>
<div class="blue">webArea</div>
<div class="green">webArea</div>
<div class="blue">webArea</div>
</body>
</html>