Skip to content

Commit

Permalink
Merge pull request #37 from zhangbobell/master
Browse files Browse the repository at this point in the history
feat(keepDefaultClass): fix behavior scope about keepDefaultClass
  • Loading branch information
zhangbobell authored Dec 20, 2017
2 parents 7efe0ce + 76f106c commit 416da42
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ data | [Page](#page)[] | []
debug | boolean | `false` | 是否开启调试模式
isVertical | boolean | `true` | 是否是垂直方向滑动
isLoop | boolean | `false` |是否开启循环翻页
keepDefaultClass | string[] | [] | 保持默认行为的 class 名,详见[说明](#about-keepdefault)
keepDefaultClasses | string[] | [] | 保持默认行为的 class 名,详见[说明](#about-keepdefault)
transition | [Transition](#transition) | `{name: 'slide', duration: 800}` | 翻页过渡动画,按照优先级取值,详见[优先级](#about-transition-priority)

**关于 keepDefaultClass 说明**<a name="about-keepdefault"></a>
**关于 keepDefaultClasses 说明**<a name="about-keepdefault"></a>

为防止滑动事件中断,Swiper 默认阻止所有除了 `a`, `input`, `textarea`, `select` 以外的所有元素的滑动事件(mouseXXX, touchXXX)默认行为。但是在实际项目中,可能还有一些元素需要被排除在外(如微信中,长按图片会有识别二维码的响应,因此就需要将该图片的 className 放入该数组中)。因此 `keepDefaultClass` 就是一个 **要保持默认响应的元素 class 的白名单**
为防止滑动事件中断,Swiper 默认阻止所有除了 `a`, `input`, `textarea`, `select` 以外的所有元素的滑动事件(mouseXXX, touchXXX)默认行为。但是在实际项目中,可能还有一些元素需要被排除在外(如微信中,长按图片会有识别二维码的响应,因此就需要将该图片的 className 放入该数组中),加入到 keepDefaultClasses 的元素及其 **后代元素** 均会被排除在外。因此 `keepDefaultClasses` 就是一个 **要保持默认响应的元素 class 的白名单**

**过渡效果优先级**<a name="about-transition-priority"></a>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fex-swiper",
"version": "1.0.1",
"version": "1.0.2",
"description": "a H5 swiper powered by FEX",
"main": "src/swiper.ts",
"repository": "http://github.com/fex-team/swiper",
Expand Down
8 changes: 5 additions & 3 deletions src/swiper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ export class Swiper {
}

let keepDefaultClasses = this.keepDefaultClasses;
for (let keepDefaultClass of keepDefaultClasses){
if (event.target.classList.contains(keepDefaultClass)) {
return;
for (let keepDefaultClass of keepDefaultClasses) {
for (let e = event.target; e !== null; e = e.parentElement) {
if (e.classList.contains(keepDefaultClass)) {
return;
}
}
}

Expand Down

0 comments on commit 416da42

Please sign in to comment.