• Stars
    star
    174
  • Rank 219,104 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight, high-performance and smooth pull element effect that support all directions

pull-element

Lightweight, high-performance and smooth pull element effect that support all directions

Features

  • Lightweight, 6kb
  • High performance, native scrolling, 60fps
  • No dependent, just vanilla.js
  • flexible, support top|right|down|left all the directions

中文版文档

Installtion

With npm

npm install --save pull-element

How to import pull-element

// ES2015 style
import PullElement from 'pull-element'

// commonjs style
var PullElement = require('pull-element')

With script tag

<script src="pull-element.js"></script>
<script>
	var pullElement = new PullElement({})
</script>

DEMO

Note: these demo were inspired by framework7

API

new PullElement(options)

PullElement is a constructor function, receive an argument options which should be an object.

Use the keyword new to get its instance, and then call the init method to initialize.

var pullElement = new PullElement(options)
pullElement.init()

Options

options.target: selector|element

target can be a selector or a dom-element, the default value is 'body'

target is used to be the target who will be setted transform|translate style when user is touching.

options.scroller: selector|element

scroller can be a selector or a dom-element, if it's empty, then the target will be the scroller

This option must works with other options detectScroll|detectScrollOnStart.

If one of detectScroll|detectScrollOnStart is true, the target will only translate when scroller reach the ending.

options.trigger: selector|element

trigger can be a selector or a dom-element, if it's empty, then the target will be the trigger.

When user is touching the trigger, it occur the pull element effect.

options.damping: number|function

damping can be a number or a function, the default value is 1.6.

If the duration of touch is x, and the damping is y, then the translate d is: d = x/y.

If damping is a function ,then d is: d = y(x).

options.pullUp: boolean

Enable pulling element up, the default value is false.

options.pullDown: boolean

Enable pulling element down, the default value is false.

options.pullLeft: boolean

Enable pulling element left, the default value is false.

options.pullRight: boolean

Enable pulling element right, the default value is false.

options.detectScroll: boolean

Enable detect scroller status, the default value is false.

When detectScroll is true, it will start pulling element when the scroller reached the ending.

If this option is true, it will detech scroll status on both touchstart and touchmove.

options.detectScrollOnStart: boolean

Enable detech scroller status on touchstart, the default value is false.

If this option is true, and detectScroll option is false, it will only detech scroll status on touchstart event.

options.stopPropagation: boolean

Enable stopPropagation on touchstart, the default value is false

This option is used to support nesting pull-element effect.

options.drag: boolean

Enable drag effect, the default value is fasle

The default behavior of pulling element is only in one axis, and translate-value of the other axis will be setted to zero.

If this option is true, the target will translate in both x-axis and y-axis.

options.transitionDuration: string

The duration of transition, the default value is 0.3s

When user stop touching, the default behavior is that target animate to the origin.

options.transitionTimingFunction: string

The timing function of transition, the default value is ease-out

When user stop touching, the default behavior is that target animate to the origin.

options.wait: boolean

Enable wait for animating to the origin, the default value is true.

When user stop touching, the default behavior is that target animate to the origin, the trigger will not response the touching event in this time.

If this options is false, user can touch the trigger again.

options.onPull{Direction}: function

Enable and response the Direction of pulling, Direction can be one of Up|Down|Left|Right.

The function will receive one argument data when user pulling the elment.

data is an object. it has two property translateX|translateY, both of them were calculated by damping.

If the function has called method this.preventDefault(), it will prevent the default behavior. In this case, target will not be setted translate style.

var pullElement = new PullElement({
	onPullUp: function(data) {
		var translateX = data.translateX
		var translateY = data.translateY
		this.preventDefault()
	}
})
pullElement.init()

options.onPull{Direction}End: function

Enable the Direction of pulling, and response the event of stop pulling, Direction can be one of Up|Down|Left|Right.

The function will receive one argument data when user pulling the elment.

data is an object. it has two property translateX|translateY, both of them were calculated by damping.

If the function has called method this.preventDefault(), it will prevent the default behavior. In this case, target will not animate to origin.

var pullElement = new PullElement({
	onPullUpEnd: function(data) {
		var translateX = data.translateX
		var translateY = data.translateY
		this.preventDefault()
	}
})
pullElement.init()

Methods

pullElement.init()

Initialize the pull-element effect, and add touch event listeners.

pullElement.destroy()

Destroy the instance of PullElement, and remove touch event listeners.

pullElement.enable()

Add touch event listeners.

pullElement.disable()

Remove touch event listeners.

pullElement.setTranslate(translateX, translateY)

Set translate style of target, translateX and translateY must be number.

You can use this method to set translate style directly after calling this.preventDefault().

pullElement.animateTo(translateX, translateY, callback)

Animate to some where, translateX and translateY is the same type in setTranslate.

The third argument callback is a function, it will be invoked when animation has been over.

If es6-promise is supported, this method will return a promise, so you can use async/await or then method to handle the ending of animation.

pullElement.animateToOrigin(callback)

Animate to origin, it's equal to this.animateTo(0, 0, callback), but more, see below.

If option wait is true, it will call animateToOrigin automatically after pull{Direction}End(Note: If you call this.preventDefault in it, you should call this.animateToOrigin manually to stop waiting).

pullElement.preventDefault()

Prevent the default behavior. This method should only be invoked by function onPull{Direction} or onPull{Direction}End

When this method is invoked by onPull{Direction}, the default behavior is this.setTranslate(translateX, translateY).

When this method is invoked by onPull{Direction}End, the default behavior is this.animateToOrigin().

License

License: MIT (See LICENSE file for details)

More Repositories

1

react-lite

An implementation of React v15.x that optimizes for small script size
JavaScript
1,726
star
2

factor-network

A simple factor network implementation written by JavaScript
JavaScript
542
star
3

Lucifier129.github.io

Lucifier129.github.io
JavaScript
410
star
4

react-imvc

An Isomorphic MVC Framework supports both SSR and CSR
JavaScript
266
star
5

Isomorphism-react-todomvc

Isomorphism javascript of todomvc powered by react and express
JavaScript
196
star
6

bistate

A state management library for React combined immutable, mutable and reactive mode
TypeScript
121
star
7

flappy-bird

flappy-bird game with time travel written by react and create-react-app
JavaScript
95
star
8

promise-aplus-impl

A simple implementation of Promise /A+ Spec
JavaScript
91
star
9

simple-machine-learning-demo

simple machine learning demo
JavaScript
64
star
10

relite

a redux-like library for managing state with simpler api
TypeScript
57
star
11

rxjs-react

make your react-component become reactive with rxjs
JavaScript
55
star
12

isomorphic-cnode

isomorphic-cnode
JavaScript
54
star
13

language-implementation-patterns

《编程语言实现模式》的相关练习
HTML
40
star
14

rust-ray-tracing-demo

The rust implementation of <Ray Tracing in One Weekend>
JavaScript
40
star
15

fetch-imgs

40 行 node.js 代码实现简易的图片爬虫
JavaScript
39
star
16

react-stateful

A simple implementation of React-State-Hook and React-Effect-Hook to show how React-Hooks work
JavaScript
34
star
17

react-use-setup

Implement the mechanism of Vue 3.0 Composition API for React based on React Hooks
TypeScript
30
star
18

coproduct

A small library aims to improve better tagged-unions/discriminated-unions supporting for TypeScript
TypeScript
29
star
19

create-app

configuring once, rendering both client and server.
TypeScript
28
star
20

the-super-tiny-jsx-compiler

the-super-tiny-jsx-compiler
JavaScript
23
star
21

react-imvc-template

react-imvc-template
JavaScript
21
star
22

functional-di

Dependency injection in functional style
TypeScript
18
star
23

next-mvc

An isomorphic mvc framework based on next.js, react, redux and immer
JavaScript
18
star
24

pure-model

A framework for writing model-oriented programming
TypeScript
16
star
25

jiandanimgs

煎蛋网高质量妹子图无广告版
JavaScript
15
star
26

monodic

Monorepo: 多项目单仓库工程管理方案
TypeScript
14
star
27

coeffect

An effect-management library for React
TypeScript
14
star
28

vdom-engine

Rethink and redesign React for Web
JavaScript
14
star
29

youmightnotneedflux

you might not need flux
JavaScript
13
star
30

gvs

Global variables sniffer
JavaScript
13
star
31

learn-webgl

some demos for learning webgl
JavaScript
13
star
32

jplus

jQuery指令插件
JavaScript
13
star
33

refer

redux-like library for handling global state on functional style
JavaScript
12
star
34

react-props

inject props to react component for high performance rendering
JavaScript
11
star
35

create-react-store

Create reactive stores for React App
TypeScript
10
star
36

react-hooks-demo

A demo based on react-hooks for show-case
JavaScript
10
star
37

training

9
star
38

graphql-dynamic

Dynamic, schema-less, directive-driven GraphQL
JavaScript
8
star
39

react-director

es2016-base router for react on decorator style
JavaScript
8
star
40

todo-imvc

todo list app powered by react-imvc
JavaScript
8
star
41

refer-dom

mvvm library base on virtural-dom and flux pattern
JavaScript
7
star
42

fe-starter

frontend-starter
JavaScript
7
star
43

costate

A state management library for react inspired by vue 3.0 reactivity api and immer
TypeScript
7
star
44

react-core-unit-testing

Use to implement your own reactjs
JavaScript
6
star
45

react-page-template

react 多页应用的模板,支持服务端渲染
JavaScript
6
star
46

umd-pack

a tool for creating library bundle file in UMD-style(forked from create-react-app)
JavaScript
5
star
47

sukkula

A state-management library aims to combine the best parts of redux and rxjs
JavaScript
5
star
48

create-react-store-todo-app

A Todo App demo powered by create-react-store
CSS
5
star
49

Agent

代理模式:将函数调用转化为配置模式
JavaScript
5
star
50

retour

an easy way to create isomorphic web app, render your page on both server-side and client-side
JavaScript
4
star
51

rxjs-animation-demo

A demo for rxjs animation
TypeScript
4
star
52

costate-examples

online demo
JavaScript
3
star
53

bistate-examples

demos for https://github.com/Lucifier129/bistate
JavaScript
3
star
54

slidev-slides

Slides via slidev
TypeScript
3
star
55

jade-incubator

Some interesting projects for POC, don't use them in production!
TypeScript
3
star
56

next-mvc-cnode

cnode web app with SSR powered by next-mvc
CSS
2
star
57

rocket-todo-app

A simple todo app powered by rocket and react
Rust
2
star
58

process

javascript 流程管理机制
JavaScript
2
star
59

jMin.js

自己写的手机端微型-类jQuery工具库
JavaScript
2
star
60

react-mvc-component

React Component in MVC style
2
star
61

isomorphism-react-file-system

同构react文件系统(娱乐项目)
JavaScript
1
star
62

jsx-template

simple jsx-template
JavaScript
1
star
63

observe.js

观察对象的属性,当它变化时,调用指定函数(更新:支持事件命名空间)。
JavaScript
1
star
64

webpack-workflow

webpack workflow for SPA
JavaScript
1
star
65

fe-tutorial

1
star
66

rx-view

react meets rxjs
JavaScript
1
star
67

static-server-toy

build static server using node.js in some different style
JavaScript
1
star
68

react-use-setup-examples

JavaScript
1
star
69

Msg

订阅者/发布者模式,自定义消息类型的工具库
JavaScript
1
star
70

esnext-framework

探究基于将来版本的 ECMAScript 框架模式
JavaScript
1
star