0.0.1 • Published 4 years ago

swipex v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

SwipeX.js

MIT SIZE VERSION

Smoothly swiper support horizontal and vertical mode.

🎉 support rax framework

>>>>>>>>>> 「source code 」<<<<<<<<<<

>>>>>>>>>> 「demo online 」<<<<<<<<<<

Quick Start

$ npm install swipex

html:

<style>
  .swipex {
    overflow: hidden;
    visibility: hidden;
  }
  .swipex-wrap {
    overflow: hidden;
  }
  .item {
    position: relative;
    float: left;
    width: 100%;
    height: 300px;
    background: #188eee;
  }
</style>

<div id="swipeX" class="swipex">
  <div class="swipex-wrap">
    <div class="item">1</div>
    <div class="item">2</div>
    <div class="item">3</div>
  </div>
</div>

javascript:

import swipeX from 'swipeX'

const container = document.getElementById('swipeX')
window.mySwipeX = SwipeX(container)

Usage

Swipex.js is a javascript library, you can custom define className in html

<div id="swipeX" class="swipex">
  <div class="swipex-wrap">
    <!-- this is your business logic  -->
    <div class="item">business logic</div>
  </div>
</div>

there is a few styles to your stylesheet

.swipex {
  /* BFC */
  overflow: hidden;
  /* init solve splash screen */
  visibility: hidden;
}
.swipex-wrap {
  /* BFC to solve */
  overflow: hidden;
}
.item {
  position: relative;
  float: left;
}

Docs

options

ParamDescriptionTypeDefault value
autoauto slideshow(milliseconds)number0
startSlidestart index positionnumber0
speedtransitions speed(milliseconds)number300
continuousloop(infinite feel)booleantrue
directionhorizontal,verticalhorizontal
stopPropagationboolean-
disableScrollstop touches on this containerboolean-
debouncedebounce for user slidebooleanfalse
frameworksupport rax frameworkrax-
swipingswiping percentage (0-1)(res: number) => void-
callbackslider change(index: number, element) => void-
transitionEndslider change (after callback )(index: number, element) => void-

Tips: 「debounce」 only work on user gesture operation, it not work at auto param or SwipeX.slide function

For example options: debounce will not work at auto mode, but it will work at user gesture operation

{
  auto: 200,
  debounce: true
}

SwipeX.method()

Include:

  • SwipeX.prev() slide to prev item
  • SwipeX.next() slide to next item
  • SwipeX.getPos() return current slide index
  • SwipeX.getNumSlides() return total slide items
  • SwipeX.slide(index: number, speed: number) slide to index item with custom speed (speed: milliseconds)
  • SwipeX.disableScrolling(disableScroll: boolean) directly control scrolling (disableScroll: same as the config option )

Example:

window.mySwipeX = SwipeX(container, {
  auto: 3000, // default: 0
  startSlide: 0, // default: 0
  speed: 300, // default: 300
  continuous: true, // can slide loop, default true
  disableScroll: false, // default : undefined
  stopPropagation: true, // default: undefined
  direction: 'horizontal', // support horizontal and vertical mode, default: 'horizontal'
  framework: 'rax', // use in rax framework, default: undefined
  callback: (index, element) => {
    console.log('callback: index - ', index, 'element - ', element)
  },
  swiping: res => {
    console.log('swiping: res - ', res) // 0 - 1
  },
  transitionEnd: (index, element) => {
    console.log('transitionEnd: index - ', index, 'element - ', element)
  },
})

contribute

clone

$ git clone https://github.com/zj1024/swipex.git

local run

install dependencies

npm install

start

npm run start

# or you can run start:your-page
npm run start:other

Tips:

  1. swipe container use css: position: fixed window.resize will unexpected

  2. width or height computed is slide item getBoundingClientRect(), if do not have slide item, it will find wrapper.