npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@truckhome/lucky-plate

v3.0.0

Published

一个大转盘

Downloads

13

Readme

结构

<div id="lucky_wheel"></div>
<link
  rel="stylesheet"
  href="https://unpkg.com/@truckhome/lucky-plate@version/dist/index.css"
/>
<script src="https://unpkg.com/@truckhome/lucky-plate@version/dist/lucky.js"></script>

css

#lucky_wheel {
}
.lucky_wheel-plate {
}
.lucky_wheel-pointer {
}

api

  1. lucky.setLuckyId(id) // 设置中奖号码
  2. lucky.getLuckyIndex() // 获取中奖是第几个
<head>
  <meta charset="utf-8" />
  <title>th-lucky-plate</title>
  <style>
    #lucky_wheel {
      margin: 0 auto;
    }
    img {
      width: 150px;
      height: 110px;
    }
  </style>
</head>
<body>
  <div id="lucky_wheel"></div>
</body>
// cdn地址:
<script src="https://unpkg.com/@truckhome/lucky-plate@version/dist/lucky.js"></script>
<script>
  const list = [
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142525-4741.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142513-8117.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142459-1375.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142437-8856.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142427-8191.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142412-2401.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142359-7538.png',
    'https://img8.kcimg.cn/HW_Image/Turntable/2022/0325/20220325142459-1375.png'
  ].map((item, index) => ({ id: index + 1, img: item }))

  let num = 1

  const lucky = new Lucky.CreateLucky({
    container: '#lucky_wheel',
    data: list,
    options: {
      // 开始方法
      start: getAsync,
      // 自定义传入Plate结构 可不传
      createPlate: data => {
        const content = data.map((item, index) =>
          `<div class="level level-${index + 1}"><figure><img src="${
            item.img
          }" /></figure></div>`.trim()
        )
        return content.join('')
      },
      // 自定义传入pointer 可不传
      createPointer: () => {
        return `<p class="lucky_pointer"></p>`
      },
      // 转到奖品回调
      callback: () => {
        console.log(111)
      }
    }
  })
  async function getAsync () {
    const id = await getId()
    console.log(id)
    lucky.setLuckyId(id)
  }

  async function getId () {
    num++
    return new Promise(resolve => {
      setTimeout(() => {
        resolve(num)
      }, 2000)
    })
  }
</script>
npm i @truckhome/lucky-plate
import {CreateLucky} from '@truckhome/lucky-plate'
import '@truckhome/lucky-plate/dist/index.css'

如果为找到类型,可以在 tsconfig.json 中 CompilerOptions.paths: {'@truckhome/lucky-plate': ['@truckhome/lucky-palte/index.d.ts']}

let lucky: CreateLucky
onMounted(() => {
  // container : document.getElementById('lucky_wheel') || '#lucky_wheel'
  lucky = new CreatLucky({
    container,
    data
  })
})
#lucky_wheel {
  position: relative;
  width: 728px;
  height: 748px;
}
.lucky_wheel-plate {
  position: absolute;
  width: 728px;
  height: 728px;
  top: 20px;
  left: 0;
  background: url('https://s.kcimg.cn/topic/images/koubei-topic/lucky-plate.png')
    no-repeat 50% 50%;
  background-size: cover;
  .level {
    position: absolute;
    &.level-1 {
      top: 70px;
      left: 50%;
      transform: translateX(-50%);
    }

    &.level-2 {
      top: 134px;
      left: 50%;
      margin-left: 48px;
    }

    &.level-3 {
      top: 276px;
      left: 50%;
      margin-left: 100px;
    }

    &.level-4 {
      top: 426px;
      left: 50%;
      margin-left: 42px;
    }

    &.level-5 {
      top: 485px;
      left: 50%;
      transform: translateX(-50%);
    }

    &.level-6 {
      top: 435px;
      left: 0;
      margin-left: 114px;
    }

    &.level-7 {
      top: 290px;
      left: 0;
      margin-left: 60px;
    }

    &.level-8 {
      top: 126px;
      left: 0;
      margin-left: 114px;
    }
  }
}
.lucky_wheel-pointer {
  position: absolute;
  width: 238px;
  height: 273px;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: url('https://s.kcimg.cn/topic/images/koubei-topic/pointer.png')
    no-repeat 50% 50%;
  background-size: cover;
  cursor: pointer;
}