Skip to content

Commit

Permalink
add default "position: relative" to container
Browse files Browse the repository at this point in the history
  • Loading branch information
yeild committed Sep 3, 2018
1 parent 224ee9d commit 1a9811e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h3><a href="https://github.com/yeild/jigsaw">返回GitHub</a></h3>
<div class="container">
<input value="admin" readonly/>
<input type="password" value="1234567890" readonly/>
<div id="captcha" style="position: relative"></div>
<div id="captcha"></div>
<div id="msg"></div>
</div>
<script src="jigsaw.js"></script>
Expand Down
13 changes: 7 additions & 6 deletions jigsaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

class jigsaw {
constructor({el, onSuccess, onFail, onRefresh}) {
el.style.position = el.style.position || 'relative'
this.el = el
this.onSuccess = onSuccess
this.onFail = onFail
Expand Down Expand Up @@ -185,9 +186,9 @@
if (e.x == originX) return false
removeClass(this.sliderContainer, 'sliderContainer_active')
this.trail = trail
const {spliced, TuringTest} = this.verify()
const {spliced, verified} = this.verify()
if (spliced) {
if (TuringTest) {
if (verified) {
addClass(this.sliderContainer, 'sliderContainer_success')
typeof this.onSuccess === 'function' && this.onSuccess()
} else {
Expand All @@ -207,13 +208,13 @@

verify() {
const arr = this.trail // 拖动时y轴的移动距离
const average = arr.reduce(sum) / arr.length // 平均值
const deviations = arr.map(x => x - average) // 偏差数组
const stddev = Math.sqrt(deviations.map(square).reduce(sum) / arr.length) // 标准差
const average = arr.reduce(sum) / arr.length
const deviations = arr.map(x => x - average)
const stddev = Math.sqrt(deviations.map(square).reduce(sum) / arr.length)
const left = parseInt(this.block.style.left)
return {
spliced: Math.abs(left - this.x) < 10,
TuringTest: average !== stddev, // 只是简单的验证拖动轨迹,相等时一般为0,表示可能非人为操作
verified: stddev !== 0 , // 简单验证下拖动轨迹,为零时表示Y轴上下没有波动,可能非人为操作
}
}

Expand Down

0 comments on commit 1a9811e

Please sign in to comment.