source/Plx.js
function parallax(scrollPosition, start, duration, startValue, endValue, easing) {
  let min = startValue;
  let max = endValue;
  const invert = startValue > endValue;


  // Safety check, if "startValue" is in the wrong format
  if (typeof startValue !== 'number') {
    console.warn(`Plx, ERROR: startValue is not a number (type: "${ typeof endValue }", value: "${ endValue }")`); // eslint-disable-line
    return null;
  }

  // Safety check, if "endValue" is in the wrong format
  if (typeof endValue !== 'number') {
    console.warn(`Plx, ERROR: endValue is not a number (type: "${ typeof endValue }", value: "${ endValue }")`); // eslint-disable-line
    return null;
  }

  // Safety check, if "duration" is in the wrong format
  if (typeof duration !== 'number' || duration === 0) {
    console.warn(`Plx, ERROR: duration is zero or not a number (type: "${ typeof duration }", value: "${ duration }")`); // eslint-disable-line
    return null;
  }

  if (invert) {
    min = endValue;
    max = startValue;
  }

  let percentage = ((scrollPosition - start) / duration);

  if (percentage > 1) {
    percentage = 1;
  } else if (percentage < 0) {
    percentage = 0;
  }

  // Apply easing
  if (easing) {
    const easingPropType = typeof easing;
    if (easingPropType === 'object' && easing.length === 4) {
      percentage = BezierEasing(
        easing[0],
        easing[1],
        easing[2],
        easing[3]
      )(percentage);
    } else if (easingPropType === 'string' && EASINGS[easing]) {
      percentage = BezierEasing(
        EASINGS[easing][0],
        EASINGS[easing][1],
        EASINGS[easing][2],
        EASINGS[easing][3]
      )(percentage);
    } else if (easingPropType === 'function') {
      percentage = easing(percentage);
    }
  }

  let value = percentage * (max - min);

  if (invert) {
    value = max - value;
  } else {
    value += min;
  }

  return parseFloat(value.toFixed(3));
}
function parallax(scrollPosition, start, duration, startValue, endValue, easing) {
  let min = startValue;
  let max = endValue;
  const invert = startValue > endValue;


  // Safety check, if "startValue" is in the wrong format
  if (typeof startValue !== 'number') {
    console.warn(`Plx, ERROR: startValue is not a number (type: "${ typeof endValue }", value: "${ endValue }")`); // eslint-disable-line
    return null;
  }

  // Safety check, if "endValue" is in the wrong format
  if (typeof endValue !== 'number') {
    console.warn(`Plx, ERROR: endValue is not a number (type: "${ typeof endValue }", value: "${ endValue }")`); // eslint-disable-line
    return null;
  }

  // Safety check, if "duration" is in the wrong format
  if (typeof duration !== 'number' || duration === 0) {
    console.warn(`Plx, ERROR: duration is zero or not a number (type: "${ typeof duration }", value: "${ duration }")`); // eslint-disable-line
    return null;
  }

  if (invert) {
    min = endValue;
    max = startValue;
  }

  let percentage = ((scrollPosition - start) / duration);

  if (percentage > 1) {
    percentage = 1;
  } else if (percentage < 0) {
    percentage = 0;
  }

  // Apply easing
  if (easing) {
    const easingPropType = typeof easing;
    if (easingPropType === 'object' && easing.length === 4) {
      percentage = BezierEasing(
        easing[0],
        easing[1],
        easing[2],
        easing[3]
      )(percentage);
    } else if (easingPropType === 'string' && EASINGS[easing]) {
      percentage = BezierEasing(
        EASINGS[easing][0],
        EASINGS[easing][1],
        EASINGS[easing][2],
        EASINGS[easing][3]
      )(percentage);
    } else if (easingPropType === 'function') {
      percentage = easing(percentage);
    }
  }

  let value = percentage * (max - min);

  if (invert) {
    value = max - value;
  } else {
    value += min;
  }

  return parseFloat(value.toFixed(3));
}
function parallax ( scrollPosition , start , duration , startValue , endValue , easing ) { let min = startValue ; let max = endValue ; const invert = startValue > endValue ; // Safety check, if "startValue" is in the wrong format if ( typeof startValue !== 'number' ) { console . warn ( ` ${ typeof endValue } ${ endValue } ` ) ; // eslint-disable-line return null ; } // Safety check, if "endValue" is in the wrong format if ( typeof endValue !== 'number' ) { console . warn ( ` ${ typeof endValue } ${ endValue } ` ) ; // eslint-disable-line return null ; } // Safety check, if "duration" is in the wrong format if ( typeof duration !== 'number' || duration === 0 ) { console . warn ( ` ${ typeof duration } ${ duration } ` ) ; // eslint-disable-line return null ; } if ( invert ) { min = endValue ; max = startValue ; } let percentage = ( ( scrollPosition - start ) / duration ) ; if ( percentage > 1 ) { percentage = 1 ; } else if ( percentage < 0 ) { percentage = 0 ; } // Apply easing if ( easing ) { const easingPropType = typeof easing ; if ( easingPropType === 'object' && easing . length === 4 ) { percentage = BezierEasing ( easing [ 0 ] , easing [ 1 ] , easing [ 2 ] , easing [ 3 ] ) ( percentage ) ; } else if ( easingPropType === 'string' && EASINGS [ easing ] ) { percentage = BezierEasing ( EASINGS [ easing ] [ 0 ] , EASINGS [ easing ] [ 1 ] , EASINGS [ easing ] [ 2 ] , EASINGS [ easing ] [ 3 ] ) ( percentage ) ; } else if ( easingPropType === 'function' ) { percentage = easing ( percentage ) ; } } let value = percentage * ( max - min ) ; if ( invert ) { value = max - value ; } else { value += min ; } return parseFloat ( value . toFixed ( 3 ) ) ; }
Calculates the current value for parallaxing property
Calculates the current value for parallaxing property