Javascript在XY轴上滚动

时间:2015-11-19 18:56:33

标签: javascript scroll

我在这里有一个jsfiddle,使用jquery 1.8.3和scrollTo来scoll到XY轴上的元素#en

https://jsfiddle.net/80kxdsxe/

var $scrollTo = $.scrollTo = function(target, duration, settings) {
    return $(window).scrollTo(target, duration, settings);
};

$scrollTo.defaults = {
    axis:'xy',
    duration: 0,
    limit:true
};

我需要工作的jsfiddle是使用纯js,但它只在X轴或Y轴上滚动到元素#en,我需要它使用XY滚动

https://jsfiddle.net/43s8wpd7/

            /* Note: In order to be subjected to chaining and animation options, scroll's tweening is routed through Velocity as if it were a standard CSS property animation. */
            if (action === "scroll") {
                /* The scroll action uniquely takes an optional "offset" option -- specified in pixels -- that offsets the targeted scroll position. */
                var scrollDirection = (/^x$/i.test(opts.axis) ? "Left" : "Top"),
                    scrollOffset = parseFloat(opts.offset) || 0,
                    scrollPositionCurrent,
                    scrollPositionCurrentAlternate,
                    scrollPositionEnd;

                if (opts.container) {
                    if (Type.isWrapped(opts.container) || Type.isNode(opts.container)) {
                        opts.container = opts.container[0] || opts.container;
                        scrollPositionCurrent = opts.container["scroll" + scrollDirection];
                        scrollPositionEnd = (scrollPositionCurrent + $(element).position()[scrollDirection.toLowerCase()]) + scrollOffset; /* GET */
                    } else {
                        opts.container = null;
                    }
                } else {
                    scrollPositionCurrent = Velocity.State.scrollAnchor[Velocity.State["scrollProperty" + scrollDirection]]; 
                    scrollPositionCurrentAlternate = Velocity.State.scrollAnchor[Velocity.State["scrollProperty" + (scrollDirection === "Left" ? "Top" : "Left")]]; /* GET */
                    scrollPositionEnd = $(element).offset()[scrollDirection.toLowerCase()] + scrollOffset; /* GET */
                }

                /* Since there's only one format that scroll's associated tweensContainer can take, we create it manually. */
                tweensContainer = {
                    scroll: {
                        rootPropertyValue: false,
                        startValue: scrollPositionCurrent,
                        currentValue: scrollPositionCurrent,
                        endValue: scrollPositionEnd,
                        unitType: "",
                        easing: opts.easing,
                        scrollData: {
                            container: opts.container,
                            direction: scrollDirection,
                            alternateValue: scrollPositionCurrentAlternate
                        }
                    },
                    element: element
                };

                if (Velocity.debug) console.log("tweensContainer (scroll): ", tweensContainer.scroll, element);

任何人都可以帮我修复第二个NON-jquery小提琴以让滚动位于XY轴上吗?

感谢。

0 个答案:

没有答案