Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import React from "react";
import classnames from "classnames";
import { clamp } from "./utils/innerSliderUtils";

import { clamp, roundToDecimal } from "./utils/innerSliderUtils";
const getDotCount = spec => {
let dots;

Expand Down Expand Up @@ -46,14 +45,14 @@ export class Dots extends React.PureComponent {
const mouseEvents = { onMouseEnter, onMouseOver, onMouseLeave };
let dots = [];
for (let i = 0; i < dotCount; i++) {
let _rightBound = (i + 1) * slidesToScroll - 1;
let _rightBound = roundToDecimal((i + 1) * slidesToScroll - 1, 2);
let rightBound = infinite
? _rightBound
: clamp(_rightBound, 0, slideCount - 1);
let _leftBound = rightBound - (slidesToScroll - 1);
let _leftBound = roundToDecimal(rightBound - (slidesToScroll - 1), 2);
let leftBound = infinite
? _leftBound
: clamp(_leftBound, 0, slideCount - 1);
: clamp(_leftBound, 0, roundToDecimal(slideCount - slidesToShow, 2));

let className = classnames({
"slick-active": infinite
Expand Down
17 changes: 12 additions & 5 deletions src/utils/innerSliderUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export function clamp(number, lowerBound, upperBound) {

export const safePreventDefault = event => {
const passiveEvents = ["onTouchStart", "onTouchMove", "onWheel"];
if(!passiveEvents.includes(event._reactName)) {
if (!passiveEvents.includes(event._reactName)) {
event.preventDefault();
}
}
};

export const getOnDemandLazySlides = spec => {
let onDemandSlides = [];
Expand Down Expand Up @@ -386,9 +386,12 @@ export const swipeMove = (e, spec) => {
let touchSwipeLength = touchObject.swipeLength;
if (!infinite) {
if (
(currentSlide === 0 && (swipeDirection === "right" || swipeDirection === "down")) ||
(currentSlide + 1 >= dotCount && (swipeDirection === "left" || swipeDirection === "up")) ||
(!canGoNext(spec) && (swipeDirection === "left" || swipeDirection === "up"))
(currentSlide === 0 &&
(swipeDirection === "right" || swipeDirection === "down")) ||
(currentSlide + 1 >= dotCount &&
(swipeDirection === "left" || swipeDirection === "up")) ||
(!canGoNext(spec) &&
(swipeDirection === "left" || swipeDirection === "up"))
) {
touchSwipeLength = touchObject.swipeLength * edgeFriction;
if (edgeDragged === false && onEdge) {
Expand Down Expand Up @@ -849,3 +852,7 @@ export const canUseDOM = () =>
window.document &&
window.document.createElement
);
export function roundToDecimal(number, decimalPlaces) {
const factor = Math.pow(10, decimalPlaces);
return Math.round(number * factor) / factor;
}