angular-scroll icon indicating copy to clipboard operation
angular-scroll copied to clipboard

How to use this with angular-ui modal?

Open poonwu opened this issue 9 years ago • 1 comments

Is it possible to accomplish this as of current version?

I tried angular.element(modal).scrollTop(0) given that modalis the modal dialog element of $uibModal. However, nothing happens.

poonwu avatar Feb 14 '16 14:02 poonwu

    var module = angular.module('myScroll', [
        'duScroll'
    ]);

    module.service('scroll', function($document) {
        this.isVisible = function(element) {
            element = $(element)[0];
            var rect = element.getBoundingClientRect();
            return rect.bottom > 0 &&
                rect.right > 0 &&
                rect.left < (window.innerWidth || document.documentElement.clientWidth) &&
                rect.top < (window.innerHeight || document.documentElement.clientHeight);
        };

        this.to = function(element) {
            element = $(element);
            if (!this.isVisible(element)) {
                // Scroll relative to modal
                var rel = element.closest('[role=dialog]').first();
                if (!rel.length) {
                    // Scroll relative to body
                    rel = $document;
                }
                // Scroll to the element
                rel.scrollToElementAnimated(element);
            }
        };
    });

Then when I call scroll.to(element) it will look for the modal parent and scroll relative to it, or fallback to scrolling relative to $document.

kmccullough avatar Sep 14 '16 15:09 kmccullough