Remove jQuery and scrollTo util
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
import { isNumeric } from './is'
|
||||
|
||||
let isAnimating = false;
|
||||
|
||||
const defaults = {
|
||||
easing: 'swing',
|
||||
headerOffset: 60,
|
||||
speed: 300
|
||||
};
|
||||
|
||||
/**
|
||||
* scrollTo is a function that scrolls a container to an element's position within that controller
|
||||
* Uses jQuery's $.Deferred to allow using a callback on animation completion
|
||||
* @param {object} $element A jQuery node
|
||||
* @param {object} options
|
||||
*/
|
||||
export function scrollTo($element, options) {
|
||||
const deferred = $.Deferred();
|
||||
|
||||
// Drop everything if this ain't a jQuery object
|
||||
if ($element instanceof jQuery && $element.length > 0) {
|
||||
|
||||
// Merging options
|
||||
options = $.extend({}, defaults, (typeof options !== 'undefined' ? options : {}));
|
||||
|
||||
// Prevents accumulation of animations
|
||||
if (isAnimating === false) {
|
||||
isAnimating = true;
|
||||
|
||||
// Default container that we'll be scrolling
|
||||
let $container = $('html, body');
|
||||
let elementOffset = 0;
|
||||
|
||||
// Testing container in options for jQuery-ness
|
||||
// If we're not using a custom container, we take the top document offset
|
||||
// If we are, we use the elements position relative to the container
|
||||
if (typeof options.$container !== 'undefined' && options.$container instanceof jQuery && options.$container.length > 0) {
|
||||
$container = options.$container;
|
||||
|
||||
if (typeof options.scrollTop !== 'undefined' && isNumeric(options.scrollTop) && options.scrollTop !== 0) {
|
||||
scrollTop = options.scrollTop;
|
||||
} else {
|
||||
scrollTop = $element.position().top - options.headerOffset;
|
||||
}
|
||||
} else {
|
||||
if (typeof options.scrollTop !== 'undefined' && isNumeric(options.scrollTop) && options.scrollTop !== 0) {
|
||||
scrollTop = options.scrollTop;
|
||||
} else {
|
||||
scrollTop = $element.offset().top - options.headerOffset;
|
||||
}
|
||||
}
|
||||
|
||||
$container.animate({
|
||||
scrollTop: scrollTop
|
||||
}, options.speed, options.easing, function() {
|
||||
isAnimating = false;
|
||||
deferred.resolve();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return deferred.promise();
|
||||
}
|
||||
1
www/assets/scripts/jquery-3.4.1.min.js
vendored
1
www/assets/scripts/jquery-3.4.1.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -46,8 +46,6 @@
|
||||
<script nomodule src="https://polyfill.io/v3/polyfill.min.js?features=fetch%2CCustomEvent%2CElement.prototype.matches" crossorigin="anonymous"></script>
|
||||
<script nomodule src="assets/scripts/abortcontroller-polyfill-only.js"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="assets/scripts/jquery-3.4.1.min.js"><\/script>')</script>
|
||||
<script src="assets/scripts/vendors.js"></script>
|
||||
<script src="assets/scripts/app.js"></script>
|
||||
</body>
|
||||
|
||||
@@ -46,8 +46,6 @@
|
||||
<script nomodule src="https://polyfill.io/v3/polyfill.min.js?features=fetch%2CCustomEvent%2CElement.prototype.matches" crossorigin="anonymous"></script>
|
||||
<script nomodule src="assets/scripts/abortcontroller-polyfill-only.js"></script>
|
||||
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="assets/scripts/jquery-3.4.1.min.js"><\/script>')</script>
|
||||
<script src="assets/scripts/vendors.js"></script>
|
||||
<script src="assets/scripts/app.js"></script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user