Skip to content

Commit

Permalink
feat: sharp text #166
Browse files Browse the repository at this point in the history
  • Loading branch information
NightCatSama committed Mar 15, 2018
1 parent 44204b4 commit 639595c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions example/dist/build.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion example/src/vue-slider/vue2-slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
</div>
</template>
<script>
// Unsharp text [#166](https://github.com/NightCatSama/vue-slider-component/issues/166)
const roundToDPR = (function () {
const r = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1
return value => Math.round(value * r) / r
})()
export default {
name: 'VueSliderComponent',
props: {
Expand Down Expand Up @@ -748,7 +754,7 @@
},
setTransform (val, isIdleSlider) {
let slider = isIdleSlider ? this.idleSlider : this.currentSlider
let value = (this.direction === 'vertical' ? ((this.dotHeightVal / 2) - val) : (val - (this.dotWidthVal / 2))) * (this.reverse ? -1 : 1)
let value = roundToDPR((this.direction === 'vertical' ? ((this.dotHeightVal / 2) - val) : (val - (this.dotWidthVal / 2))) * (this.reverse ? -1 : 1))
let translateValue = this.direction === 'vertical' ? `translateY(${value}px)` : `translateX(${value}px)`
let processSize = this.fixed ? `${this.fixedValue * this.gap}px` : `${slider === 0 ? this.position[1] - val : val - this.position[0]}px`
let processPos = this.fixed ? `${slider === 0 ? val : (val - this.fixedValue * this.gap)}px` : `${slider === 0 ? val : this.position[0]}px`
Expand Down
8 changes: 7 additions & 1 deletion src/vue2-slider.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
</div>
</template>
<script>
// Unsharp text [#166](https://github.com/NightCatSama/vue-slider-component/issues/166)
const roundToDPR = (function () {
const r = typeof window !== 'undefined' ? window.devicePixelRatio || 1 : 1
return value => Math.round(value * r) / r
})()
export default {
name: 'VueSliderComponent',
props: {
Expand Down Expand Up @@ -748,7 +754,7 @@
},
setTransform (val, isIdleSlider) {
let slider = isIdleSlider ? this.idleSlider : this.currentSlider
let value = (this.direction === 'vertical' ? ((this.dotHeightVal / 2) - val) : (val - (this.dotWidthVal / 2))) * (this.reverse ? -1 : 1)
let value = roundToDPR((this.direction === 'vertical' ? ((this.dotHeightVal / 2) - val) : (val - (this.dotWidthVal / 2))) * (this.reverse ? -1 : 1))
let translateValue = this.direction === 'vertical' ? `translateY(${value}px)` : `translateX(${value}px)`
let processSize = this.fixed ? `${this.fixedValue * this.gap}px` : `${slider === 0 ? this.position[1] - val : val - this.position[0]}px`
let processPos = this.fixed ? `${slider === 0 ? val : (val - this.fixedValue * this.gap)}px` : `${slider === 0 ? val : this.position[0]}px`
Expand Down

0 comments on commit 639595c

Please sign in to comment.