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

react-swipers-evar

v1.0.0

Published

react swiper evar 组件

Downloads

2

Readme

react-swipers### 安装

npm i react-swipers --save

使用

原理

swipes不依赖任何css,不会去改变子item的样式,也就是说,css完全控制在自己的代码中。所以有必要了解卡片滑动的原理:

<!-- 三层滑动原理,动的是第二层 -->
<!-- 基础样式需要自己编写 -->
<!-- 第一层设置固定宽度 ,超过部分设置为不显示 overflow: hidden;   -->
<div >  
    <!-- 第二层设置为实际需要的宽度,即子div的n倍,有间距需要算上间距 -->
    <div>  
        <!-- 第三层,实际item 内容的宽度 -->
        <div></div>  
    </div>  
</div>

这是滑动的基础布局,最终的滑动也就是改变第二层div的translateX值。再加上transition 过渡效果,即可实现整个区域的运动,而最外层元素设置了溢出隐藏,这样整体效果就是单张卡片在运动了。

具体使用

    import ReactSwipe from 'react-swipers'
    
    // swipers 的配置
    let opt = {
    distance: 620, // 每次移动的距离,卡片的真实宽度
    currentPoint: 1,// 初始位置,默认从0即第一个元素开始
    autoPlay: true, // 是否开启自动播放
    interval: 2000,  // 幻灯片切换时间,默认2000ms
    swTouchstart: (ev) => {

    },
    swTouchmove: (ev) => {

    },
    swTouchend: (ev) => {
        let data = {
            moved: ev.moved,
            originalPoint: ev.originalPoint,
            newPoint: ev.newPoint,
            cancelled: ev.cancelled
        }
        console.log(data);
        this.setState({
            curCard: ev.newPoint
        })
    }
    }
    
    // dom 部分
    // 第一层div
    <div className="card-swipe">
        // 第二层div  react-swipes生成一个className为 card-slide的div
        <ReactSwipe className="card-slide" options={ opt }>
            // 第三层,即本身的item
            this.state.card.length && this.state.card.map((item, index) => <div className="item" key={index}> </div>
        </ReactSwipe>
    </div>

demo

sandbox demo

todo

  • 现在把css完全暴露给使用者了,这样第二层div的宽度(第三层元素的宽度和)需要大家在代码中计算,不是很方便,后续会把这块逻辑放到组件里面去,开发者只需要配置卡片基础属性即可。
  • 卡片滑动过程想实现类似上面的缩放效果,目前需要在 swTouchmove swTouchend 钩子里面自己去实现,后面会把这个效果做到组件里面去,开发者选择是否开启。