半模态转场回弹效果和底部按钮固定demo ?

半模态转场回弹效果和底部按钮固定

阅读 382
avatarAI BotBETA

半模态转场回弹效果和底部按钮固定demo是一个用于展示模态窗口转场动画和底部按钮固定的效果。这种效果通常在移动应用程序中实现,用于提供更好的用户体验。

在半模态转场回弹效果中,当用户与模态窗口进行交互时,模态窗口将通过动画效果移动到屏幕中心,同时回弹到初始位置。这种效果可以增加用户的参与度和互动性,使模态窗口更加吸引人。

底部按钮固定是指在模态窗口中固定一个或多个按钮,这些按钮始终保持在屏幕底部,以便用户可以轻松地点击它们。这种设计可以改善用户的使用体验,特别是对于那些需要频繁点击按钮的用户。

以下是一个简单的示例代码,演示如何在 HTML 和 CSS 中实现半模态转场回弹效果和底部按钮固定:

HTML:

<div class="modal">
  <div class="modal-content">
    <h1>Modal Window</h1>
    <p>This is a modal window with a fixed button at the bottom.</p>
    <button class="modal-close">Close</button>
    <button class="modal-action">Action</button>
  </div>
</div>

CSS:

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: auto;
}

.modal-content {
  background-color: #fff;
  padding: 20px;
  width: 80%;
  max-width: 600px;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 5px 10px;
  background-color: #333;
  color: #fff;
  border: none;
  cursor: pointer;
}

.modal-action {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 15px;
  background-color: #333;
  color: #fff;
  border: none;
  cursor: pointer;
}
1 个回答

示例代码

@Entry 
@Component 
struct Index { 
  @State isShow: boolean = false 
  build() { 
    Column() { 
      Row() { 
        Button() { 
          Text("弹出").fontSize(18).backgroundColor(Color.Black).fontColor(Color.White) 
        }.onClick(() => { 
          this.isShow = true 
        }) 
 
        Blank() 
        Button() { 
          Text("关闭").fontSize(18).backgroundColor(Color.Black).fontColor(Color.White) 
        }.onClick(() => { 
          this.isShow = false 
        }) 
      }.padding(25) 
      .width('100%') 
 
      Panel(this.isShow) { 
        Column() { 
          Text('撕膜啥的太麻烦,所以我不买这个车').fontColor(Color.Gray) 
          Divider() 
          Text('回复').height(50) 
            .onClick(() => { 
              this.isShow = false 
            }) 
          Divider() 
          Text('转发').height(50) 
            .onClick(() => { 
              this.isShow = false 
            }) 
          Divider() 
          Text('复制').height(50) 
            .onClick(() => { 
              this.isShow = false 
            }) 
          Divider() 
          Text('投诉').height(50) 
            .onClick(() => { 
              this.isShow = false 
            }) 
          Button() { 
            Text("取消").fontColor(Color.Black) 
          } 
          .height(50) 
          .backgroundColor(Color.Gray) 
          .width('80%') 
          .borderRadius(20) 
          .onClick(() => { 
            this.isShow = false 
          }) 
        }.width("100%") 
      } 
      .zIndex(0) 
      .type(PanelType.Foldable) 
      .mode(PanelMode.Full) 
      .fullHeight(380) 
      .dragBar(true) 
      .backgroundMask(Color.Transparent) 
      .onChange((width: number, height: number, mode: PanelMode) => { 
      }) 
 
      if (this.isShow) { 
        Button() { 
          Text("取消").fontColor(Color.Black) 
        } 
        .height(50) 
        .backgroundColor(Color.Gray) 
        .width('80%') 
        .borderRadius(20) 
        .position({ x: 0, y: '100%' }) 
        .markAnchor({ x: 0, y: '100%' }) 
        .onClick(() => { 
          this.isShow = false 
        }) 
        .zIndex(100) 
      } 
    } 
 
    .height('100%').width('100%') 
  } 
 } 
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进