当前位置: 首页 > article >正文

列表自动向上滚动

列表自动向上滚动 鼠标放上去 自动停止滚动

  <div id="list-detail-main">
    <div class="my_table_thead_tr">
      <div v-for="(item, index) in header" :key="index" class="my_table_thead_th">
        {{ item }}
      </div>
    </div>
    <div
      ref="contentScroll"
      class="my_table_tbody"
      @mousemove="move"
      @mouseleave="leave"
      @mousewheel="wheel"
    >
      <div v-for="(item, ind) in dataset" :key="ind" class="my_table_tbody_tr">
        <div
          v-for="(value, index) in item"
          :key="index"
          class="my_table_tbody_td"
          :class="[{ is_special_col: index === 0 }]"
        >
          {{ value }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts" name="SickDetailListDetailComponent">
import { ref, onBeforeUnmount, onUnmounted, watch } from 'vue';

const props = defineProps({
  header: {
    type: Array,
    default: () => [],
  },
  dataset: {
    type: Array,
    default: () => [],
  },
});
// 定时器初始化
const timer = ref();
// content实例
const contentScroll = ref();

watch(
  () => props.dataset,
  () => {
    if (props.dataset.length > 6) {
      start();
    }
  },
  {
    deep: true,
  },
);

onBeforeUnmount(() => {
  // 清除定时器
  clearTimeout(timer.value);
});

onUnmounted(() => {
  // 清除定时器
  clearTimeout(timer.value);
});

/**
 * @Description: 鼠标移动事件
 * @Author: TQ
 */
function move() {
  clearTimeout(timer.value);
}
/**
 * @Description: 鼠标离开事件
 * @Author: TQ
 */
function leave() {
  if (props.dataset.length > 6) {
    start();
  }
}

const wheel = (e) => {
  if (e.deltaY > 0) {
    contentScroll.value.scrollTop += 10;
  } else {
    contentScroll.value.scrollTop -= 10;
  }
};

// 开启定时器方法
function start() {
  // 清除定时器
  clearTimeout(timer.value);
  // 定时器触发周期
  const speed = ref(75);
  timer.value = setInterval(scrollCore, speed.value);
}

// 滚动事件核心
function scrollCore() {
  // 判断组件是否渲染完成
  // 如果列表数量过少不进行滚动
  if (contentScroll.value.childNodes.length < 6) {
    clearTimeout(timer.value);
    return;
  }
  // 组件进行滚动
  contentScroll.value.scrollTop += 1;
  // 判断滚动条是否滚动到底部
  if (
    contentScroll.value.scrollTop ===
    contentScroll.value.scrollHeight - contentScroll.value.clientHeight
  ) {
    // 获取组件第一个节点
    const a = contentScroll.value.childNodes[0];
    // 删除节点
    contentScroll.value.removeChild(a);
    // 将该节点拼接到组件最后
    contentScroll.value.append(a);
  }
}
</script>

<style lang="scss" scoped>
.is_special_col {
  color: #c4c4c4 !important;
  text-align: left !important;
}

#list-detail-main {
  padding-bottom: 20px;
  padding-left: 16px;
  pointer-events: auto;

  .my_table_thead_tr {
    display: flex;
    justify-content: space-between;
    width: 432px;
    padding: 0 8px;

    .my_table_thead_th {
      color: #356eff;
    }
  }

  .my_table_tbody {
    width: 432px;
    height: 220px;
    margin-top: 5px;
    overflow: hidden;

    .my_table_tbody_tr {
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 40px;
      padding: 0 8px;
      margin: 5px 0;
      background-color: #0f1726;
      border: 1px solid transparent;

      &:hover {
        border: 1px solid #d5f31d;
      }

      .my_table_tbody_td {
        font-size: 12px;
        color: #5fe3ff;
        text-align: center;

        &:first-child {
          width: 80px;
        }

        &:nth-child(2) {
          width: 64px;
        }

        &:nth-child(3) {
          width: 80px;
        }

        &:nth-child(4) {
          width: 64px;
        }

        &:last-child {
          width: 64px;
        }
      }
    }
  }
}
</style>


http://www.kler.cn/news/107303.html

相关文章:

  • 【Android内存优化】内存泄露优化之强引用变弱引用完全详解
  • ElasticSearch快速入门实战
  • ConcurrentHashMap 的 size()方法是线程安全的吗?为什么
  • 程序生活 - 减肥小记
  • C复习-指针
  • WPF:自定义按钮模板
  • xxl-job-架构及原理
  • 【24种设计模式】单例模式(Singleton Pattern)
  • 基于MATLAB的电流、电压互感器特性的仿真分析
  • 数据库MySQL(六):事务
  • vue + html + Lodop打印功能
  • 归结原理、归结演绎推理
  • Qt中设置鼠标透明度的应用及示例
  • 计网小题题库整理第一轮(面向期末基础)(3)
  • Spring Boot Actuator 介绍
  • (二开)Flink 修改源码拓展 SQL 语法
  • 数据结构 | 算法的时间复杂度和空间复杂度【详解】
  • Android---Bitmap详解
  • 【计网 Socket编程】 中科大郑烇老师笔记 (九)
  • 基于单片机的温湿度检测及远程控制系统设计
  • rest参数
  • STM32 CubeMX配置USB HID功能,及安装路径
  • 【Python机器学习】零基础掌握SimpleImputer缺失值填充
  • 牛客网刷题-(7)
  • PDF 文档处理:使用 Java 对比 PDF 找出内容差异
  • Qt QMetaObject::invokeMethod
  • 【C语言】【goto语句】复习捡拾~
  • vue使用AES加解密
  • vue3-vite-ts-pinia
  • Linux命令(106)之rename