


在代码中搜索关键字NestedScrollMode,发现设置滚动方式为PARENT_FIRST,父组件优先滚动到边缘后自身滚动。以下是相关代码:
import webview from "@ohos.web.webview";
@Entry
@Component
struct NestedScroll {
private scrollerForScroll: Scroller = new Scroller();
private web = new webview.WebviewController();
build() {
Flex() {
Scroll(this.scrollerForScroll) {
Column() {
Column(){
Text("Scroll Area1.1")
.width("100%")
.height("5%")
.backgroundColor(0X330000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
Text("Scroll Area1.2")
.width("100%")
.height("5%")
.backgroundColor(0X330000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
Text("Scroll Area1.3")
.width("100%")
.height("5%")
.backgroundColor(0X330000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
}
Column(){
Text("Scroll Area2.1")
.width("100%")
.height("5%")
.backgroundColor(0X540000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
Text("Scroll Area2.2")
.width("100%")
.height("5%")
.backgroundColor(0X540000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
}
Web({
src: $r('app.string.test_url'), // 测试时请替换成实际地址
controller: this.web
})
.width("100%")
.height("100%")
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
.fileAccess(false)
.geolocationAccess(false)
}
}
.width("100%")
.height("100%")
}
.width('100%')
.height('100%')
.backgroundColor(0xDCDCDC)
.padding({
left: 20,
right: 20,
top: 50,
bottom: 20
})
}
} import webview from "@ohos.web.webview";
@Entry
@Component
struct NestedScroll {
private scrollerForScroll: Scroller = new Scroller();
private web = new webview.WebviewController();
build() {
Flex() {
Scroll(this.scrollerForScroll) {
Column() {
Column(){
Text("Scroll Area1.1")
.width("100%")
.height("5%")
.backgroundColor(0X330000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
Text("Scroll Area1.2")
.width("100%")
.height("5%")
.backgroundColor(0X330000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
Text("Scroll Area1.3")
.width("100%")
.height("5%")
.backgroundColor(0X330000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
}
Column(){
Text("Scroll Area2.1")
.width("100%")
.height("5%")
.backgroundColor(0X540000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
Text("Scroll Area2.2")
.width("100%")
.height("5%")
.backgroundColor(0X540000FF)
.fontSize(16)
.textAlign(TextAlign.Center)
}
Web({
src: $r('app.string.test_url'), // 测试时请替换成实际地址
controller: this.web
})
.width("100%")
.height("100%")
.hitTestBehavior(HitTestMode.Block)
.fileAccess(false)
.geolocationAccess(false)
}
}
.width("100%")
.height("100%")
}
.width('100%')
.height('100%')
.backgroundColor(0xDCDCDC)
.padding({
left: 20,
right: 20,
top: 50,
bottom: 20
})
}
}