首页 > 其他分享 >实战13-搜索模块滑动效果01

实战13-搜索模块滑动效果01

时间:2024-09-14 21:50:46浏览次数:3  
标签:13 01 .. fontColor 100% width import 滑动 255

import { getHomeDataApi } from '../api/home';
import { BannerListDataSource, INavList, IPlanList, ITitleList } from '../api/models/HomeData';
import SwiperLayout from '../views/Home/SwiperLayout';
import { window } from '@kit.ArkUI';
import NavList from '../views/Home/NavList';
import { PADDING, SHADOW_RADIUS } from '../constants/size';
import SearchBar from '../views/Home/SearchBar';
import TitleList from '../views/Home/TitleList';
import PlanList from '../views/Home/PlanList';
import RoomRecommend from '../views/Home/RoomRecommend';

@Entry
@Component
export default struct Home {
  @State bannerList: BannerListDataSource = new BannerListDataSource()
  @State navList: INavList = []
  @State titleList: ITitleList = []
  @State planList: IPlanList = []
  @State adPicure: string = ''
  //获取首页数据的函数
  getHomeData = async () => {
    const result = await getHomeDataApi()
    this.bannerList.setList(result.bannerList)
    this.navList = result.navList;
    this.titleList = result.titleList;
    this.planList = result.planList;
    this.adPicure = result.adPicTure;

  }
  //存储滚动条位置(Y轴滚动距离)
  scrollY: number = 0;
  @State bgColor: string = 'rgba(0,0,0,0)'
  @State fontColor: string = 'rgba(255,255,255,1)'

  //生命周期函数:初始化渲染时候
  aboutToAppear(): void {
    this.getHomeData()

    window.getLastWindow(getContext())
      .then(win => {
        win.setWindowLayoutFullScreen(true)
      })
  }

  //处理滚动事件
  handleScroll = (xOffset: number, yOffset: number) => {
    //更新滚动距离
    this.scrollY += yOffset
    //计算颜色
    this.calcColor()
  }
  calcColor = () => {
    if (this.scrollY < 10) {
      //到达顶部 渐变开始
      this.bgColor = 'rgba(0,0,0,0)'
      this.fontColor = 'rgba(255,255,255,1)'
    } else if (this.scrollY < 100) {
      //渐变中(透明度0->1)
      const colorOpacity = (this.scrollY - 10) / (100 - 10)
      this.bgColor = `rgba(255,255,255,${colorOpacity})`
      this.fontColor = `rgba(0,0,0,${colorOpacity})`
    } else {
      //渐变全部完成
      this.bgColor = 'rgba(255,255,255)'
      this.fontColor = 'rgba(0,0,0)'
    }
  }

  build() {
    Stack() {
      Scroll() {
        Column() {
          //轮播图组件
          SwiperLayout({ bannerList: this.bannerList })
          Column() {
            //导航栏
            NavList({ navList: this.navList })
            // TitleList
            TitleList({ titleList: this.titleList })
            //计划列表
            PlanList({ planList: this.planList })
            //广告
            Image(this.adPicure)
              .width('100%')
              .height(60)
              .objectFit(ImageFit.Fill)
              .shadow(
                {
                  offsetX: 0,
                  offsetY: 0,
                  radius: SHADOW_RADIUS,
                  color: 'rgba(0,0,0.14)'
                }
              )
              .margin({ top: 10 })
          }
          .width('100%').padding({ left: PADDING, right: PADDING })

          //房源推荐
          RoomRecommend()
        }.width('100%')

      }
      .width('100%')
      .height('100%')
      .scrollBar(BarState.Off)
      .align(Alignment.TopStart)
      .onDidScroll(this.handleScroll)

      //搜索区
      SearchBar({ bgColor: this.bgColor, fontColor: this.fontColor })
    }.width('100%').alignContent(Alignment.TopStart)
  }
}

红色文字是新增或者修改的内容。

import { PADDING } from '../../constants/size';

@Component
export default struct SearchBar {
  @Prop bgColor: string;
  @Prop fontColor: string;

  build() {
    Row({ space: 16 }) {
      Text("长春").fontSize(14).fontColor(this.fontColor)
      Stack() {
        TextInput().width('100%').height('100%').backgroundColor($r('app.color.white')).border({
          width: 1,
          color: $r('app.color.gray')
        });
        Row() {
          Image($r('app.media.search')).width(18).height(18)
          Text('公司/地铁/小区 马上搜索')
            .fontSize(10)
            .fontColor($r('app.color.gray'))
            .layoutWeight(1)
            .margin({ left: 10, right: 10 })
          Column() {
          }.width(1).height(18).backgroundColor("#D7D7D7").margin({ right: 16 })

          Image($r('app.media.position')).width(18).height(18)
        }.width('100%').padding({ left: 16, right: 16 })
      }.width(244)

      Image($r('app.media.message')).width(24).height(24).fillColor(this.fontColor)
    }
    .width('100%')
    .height(38)
    .padding({
      left: PADDING,
      right: PADDING,
      top: 4,
      bottom: 4
    })
    .margin({ top: 4 })
    .backgroundColor(this.bgColor)
  }
}

 

标签:13,01,..,fontColor,100%,width,import,滑动,255
From: https://blog.csdn.net/weixin_43980468/article/details/142266836

相关文章

  • 2024.9.13 总结(考 DP)
    (实际上是2024.9.14写的)本来以为是考DS的。()T1题目里给的那个性质可能是来干扰的。异或上右移一位的数,其实就是除了第一位(最左边的),算贡献的时候都要看这一位异或前一位是不是1。于是随便线性DP,状态里记一下当前位填0还是1就行了。DP数组状态的第一维可以不要,省空......
  • [安洵杯 2019]easy_web
    首先抓包可以看到img是一个base64编码依次经过base64,base64,asciihex解码得到一个图片名555.png那么我们可以利用这一点反过去看index.php的源码,修改头img=TmprMlpUWTBOalUzT0RKbE56QTJPRGN3最后经过base64解码后<?phperror_reporting(E_ALL||~E_NOTICE);header('con......
  • 滑动窗口算法—最小覆盖子串
    题目         ”最小覆盖子串“问题,难度为Hard,题目如下:        给你两个字符串S和T,请你在S中找到包含T中全部字母的最短子串。如果S中没有这样一个子串,则算法返回空串,如果存在这样一个子串,则可以认为答案是唯一的。    比如输入S="ADB......
  • 201 Introducing Mutations - A Better Way of Changing Data
    在Vue中,Mutations是Vuex状态管理模式中的重要组成部分。Mutations主要用于更改Vuex中的状态。它提供了一种集中且规范的方式来修改应用的全局状态数据。每个Mutation都是一个函数,函数接收当前的状态作为第一个参数,通过对状态的直接修改来实现状态的变更。Mutatio......
  • MAST20018 – Discrete Mathematics and Operations Research
    MAST20018 – Discrete Mathematics and Operations ResearchAssignment 3Upload to Gradescope by 5pm Wed 18th September 2024Question 1In assignment 1, you considered the following project with 8 activities, labelled A to H:......
  • FIT5137 M-Stay Residential service
    FIT5137Assignment2-S22024 (Weight=40%)Due-Friday,20September2024,4:30PMGeneralInformationandSubmissiono Thisisanindividualassignment.o Submissionmethod:SubmissionisonlinethroughMoodle.o Penaltyforlatesubmission:5%deduc......
  • 【csp201912-2】回收站选址
    题目背景 开学了,可是校园里堆积了不少垃圾杂物。 热心的同学们纷纷自发前来清理,为学校注入正能量~题目描述通过无人机航拍我们已经知晓了n处尚待清理的垃圾位置,其中第i(1≤i≤n)处的坐标为(x,y),保证所有的坐标均为整数。我们希望在垃圾集中的地方建立些回收站。具体来说,对......
  • 南沙C++noip老师解一本通题: 1360:奇怪的电梯(lift)
    ​【题目描述】大楼的每一层楼都可以停电梯,而且第i层楼(1≤i≤N)上有一个数字Ki(0≤=Ki≤=N)。电梯只有四个按钮:开,关,上,下。上下的层数等于当前楼层上的那个数字。当然,如果不能满足要求,相应的按钮就会失灵。例如:33125代表了Ki(K1=3,K2=3,……),从一楼开始。在一楼,按“上”可以到4......
  • 章13——常用类——包装类,Integer类
    包装类ctrl+b可以跳转源代码。char和boolean的继承体系:包装类和基本数据的转换//装箱intn=200;Integerinteger=n;//拆箱intn1=integer;包装类练习题三元运算符中是一个整体,其中精度最高的是double,所以无......
  • 合宙Air201资产定位模组LuatOS课程:GPS/LBS/Wi-Fi定位
    已经推出3期课程啦:helloworld、点灯、远程控制,小伙伴们是不是收获满满,期待更高阶的应用呢?本期,我们将学习合宙Air201的核心功能之一——定位功能!Air201定位示例教程  合宙Air201资产定位模组——是一个集成超低功耗4G通信、语音通话、超低功耗定位、计步、震动、Type-C、充电、放......