基于VUE构建做题H5组件【附源代码】

实现功能:

  1. 题目的加载
  2. 文章的上下滑动
  3. 做题模式
  4. 做题内容区域的上下滑动动态调整做题区域
  5. 左右滑动切换题目
  6. 计时功能
  7. 提交限制功能
  8. 字体大小调节
  9. 背景颜色调节
  10. 网络错误提示窗
  11. 做题选中逻辑

首先遇到的问题是做题区域与文章区域上下滑动的问题
怎样才能自适应屏幕呢

首先在 created函数里,获取当前屏幕的高度

this.clientHeight = document.documentElement.clientHeight
      this.position = this.clientHeight / 2
      this.positionEnd = this.clientHeight / 2

后来经过多方面调研,发现没有适合的分屏插件
于是决定自己写截屏插件

大体思路如下

  1. 利用touch.js来侦测手指在屏幕中的滑动事件
  2. 根据获得的参数,计算出做题区域与文章展示区域的高度变化
  3. 根据高度变化,改变文章显示区域的高度。做题区域自动补全剩下的高度

代码如下

onPanup (e) {
        this.aniM = false
        console.log(this.clientHeight - this.position)
        if (this.clientHeight - this.position <= 200) {
          this.position = this.clientHeight - 200
          this.contentHeight = this.position + 'px'
          return false
        } else {
          this.position = e.deltaY + this.positionEnd
          this.contentHeight = this.position + 'px'
          let child = document.getElementsByClassName('setHeight')
          if (this.examStatus) {
            for (var i = 0; i < child.length; i++) {
              child[i].setAttribute('style', 'padding-bottom:50px;height:' + (this.clientHeight - this.position - 100) + 'px')
            }
          } else {
            for (var j = 0; j < child.length; j++) {
              child[j].setAttribute('style', 'height:' + (this.clientHeight - this.position - 80) + 'px')
            }
          }
        }
      },
      setH () {
        let child = document.getElementsByClassName('setHeight')
        if (this.examStatus) {
          for (var i = 0; i < child.length; i++) {
            child[i].setAttribute('style', 'padding-bottom:50px;height:' + (this.clientHeight - this.position - 100) + 'px')
          }
        } else {
          for (var j = 0; j < child.length; j++) {
            child[j].setAttribute('style', 'height:' + (this.clientHeight - this.position - 80) + 'px')
          }
        }
      },
onPanend (e) {
  if (this.clientHeight - this.position <= 200) {
    this.position = this.clientHeight - 201
    this.positionEnd = this.clientHeight - 201
  } else {
    this.positionEnd = this.positionEnd + e.deltaY
  }
},

时间转换的函数
由秒转换XX:XX的格式

startTime () {
        this.startTimeTop ++
        this.timeTrans(this.startTimeTop)
        setTimeout(() => {
          this.startTime()
        }, 1000)
      },

      // 时间转换
      timeTrans (val) {
        let f = parseInt(val / 60)
        let m = val % 60
        if (f < 10) {
          f = '0' + f
        }
        if (m < 10) {
          m = '0' + m
        }
        this.time.f = f
        this.time.m = m
      },

测试网址点我跳转(手机打开或浏览器仿真)

github仓库地址git链接

https://github.com/fanshyiis/...
有用记得点个星

https://www.enjoyreading.net/...

扫码也可以
clipboard.png

上几张效果图

WechatIMG58.jpeg

WechatIMG59.jpeg

WechatIMG60.jpeg

WechatIMG61.jpeg

WechatIMG62.jpeg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值