Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

y-tour

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

y-tour

漫游式导航

latest
npmnpm
Version
1.0.1
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/a88c07f29a244612b1a7c94a11110569~tplv-k3u1fbpfcp-zoom-crop-mark:3024:3024:3024:1702.awebp?

安装

npm install -s y-tour

使用

<template>
  <!-- ...
    模版里随便写些内容,加上class或id
  ... -->
  <!-- 使用组件 -->
  <Tour ref="tourRef" v-model:show="showTour" :steps="steps">
      <!-- 使用插槽 -->
      <template #title="data">
        {{data.title}}
      </template>
  </Tour>
</template>
<script setup lang="ts">
import {onMounted, reactive, Ref, ref} from "vue";
import {Step} from "y-tour/src/TourHandler";
// 引入组件
import Tour from "y-tour";

// 控制导航是否展示
const showTour = ref(false)
// 导航组件实例
const tourRef = ref()

// 定义步骤信息
const steps: Step[] = [{
  el: ()=>document.getElementsByClassName('first-but')[0] as HTMLElement,
  beforeActive:(run)=>{
    // 有些情况dom元素不在窗口内,需要先滚动滚动条,然后调用run方法
    document.getElementsByClassName('tour-text')[0].scrollTo({top: 0})
    run()
  },
  title: '下一步',
  description: '点击这里可进行下一步操作'
},{
  el: ()=>document.getElementsByClassName('step-two')[0] as HTMLElement,
  placement: 'top',
  beforeActive:(run, getRect)=>{
    const {targetRect} = getRect()
    let scroll = targetRect.bottom<0? 10-targetRect.bottom:targetRect.bottom
    document.getElementsByClassName('tour-text')[0].scrollTo({top: scroll})
    run()
  },
  title: '第二部',
  description: '点击这个进入第二步'
},{
  el: ()=>document.getElementsByClassName('logo')[0] as HTMLElement,
},{
  el: ()=>document.getElementsByClassName('step-aaa')[0] as HTMLElement,
  beforeActive:(run, getRect)=>{
    const {targetRect} = getRect()
    let scroll = targetRect.top<0? -targetRect.top-10:targetRect.top
    document.getElementsByClassName('tour-text')[0].scrollTo({top: scroll})
    run()
  },
  title: '取消',
  description: '点击这里可取消操作'
},{
  el: ()=>document.getElementsByClassName('four-but')[0] as HTMLElement,
  beforeActive:(run)=>{
    document.getElementsByClassName('tour-text')[0].scrollTo({top: 0})
    run()
  }
},{
  el: ()=>document.getElementsByClassName('five-step')[0] as HTMLElement,
  beforeActive:(run)=>{
    document.getElementsByClassName('tour-text')[0].scrollTo({top: 0})
    run()
  }
},]

// 必须等页面挂在完成后才可以开始导航,否则获取不到dom节点
onMounted(()=>{
  // 打开导航可以使用v-model:show,也可以直接调用组件的open方法
  showTour.value = true
  // tourRef.value.open()
})
</script>

属性

属性名说明类型默认值
show / v-model:show是否显示booleanfalse
current / v-model:current当前步骤number0
steps步骤列表Step[][]
mask是否显示遮罩层booleantrue

Step

interface Step{
    el: ()=>HTMLElement,
    title?: string,
    description?: string,
    placement?: 'top'|'bottom'|'left'|'right',
    beforeActive?: (run: (rectMap?: RectMap)=>void, getRect: ()=>RectMap)=>void,
    afterActive?: ()=>void
}
  • beforeActive钩子函数的参数为 run函数和getRect函数。

  • 调用getRect可以获得这次窗口渲染的位置信息RectMap

  • 调用run函数才能渲染本次步骤

  • run函数接受RectMap作为参数

  • 可以调用getRect获取RectMap,并对其进行修改,最后调用run函数即可实现对渲染的结果的影响

事件

事件名说明类型
open导航被打开Function
close导航被关闭Function
change步骤切换Function
next点击了下一步Function
last点击了上一步Function

方法

方法名说明类型
open打开导航Function
close关闭导航Function
last切换上一步Function
next切换下一步Function

插槽

名称说明
default覆盖整个弹窗
title覆盖标题
close覆盖关闭按钮
description覆盖描述
footer覆盖底部

Keywords

vue3

FAQs

Package last updated on 25 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts