glide icon indicating copy to clipboard operation
glide copied to clipboard

browser resize breaks it

Open sorsenne opened this issue 13 years ago • 4 comments

works like a charm but when i resize the browser (or change mobile orientation), the slider doesn't update its size.

is there a way to 'restart' the slider?

sorsenne avatar Nov 27 '13 16:11 sorsenne

I changed windows resize function for that.. This way its not try to resize browser million times when resizing window. this way when you relase screen, function wil fire once. but the right way is plugin owner can add this future and let users set delay time. I set delay time to 500 ms.

line 139 ;

    /**
     * Controller
     * When resize browser window
     * Pause autoplay in fear of escalation
     * Reinit plugin for new slider dimensions
     * Correct crop to current slide
     * Start autoplay from beginning
     */
    $(window).on({
        orientationchange: Debouncer(function (e) {
            // Reinit plugin (set new slider dimensions)
            _.init();
            // Crop to current slide
            _.slide(0);
        }), resize: Debouncer(function (e) {
            // Reinit plugin (set new slider dimensions)
            _.init();
            // Crop to current slide
            _.slide(0);
        })
    });

    // Window Resize Debouncer
    function Debouncer(func, timeout) {
        var timeoutID, timeout = timeout || 500;
        return function () {
            var scope = this, args = arguments;
            clearTimeout(timeoutID);
            timeoutID = setTimeout(function () {
                func.apply(scope, Array.prototype.slice.call(args));
            }, timeout);
        }
    }

SenerPhoenix avatar Nov 27 '13 18:11 SenerPhoenix

Yeah, this may be caused by a multitude of calculations. But on all devices, which it was tested, there was never such a problem.

To reinit slider you need to:

// Calculate slider elements dimensions
_.init()
// Reset slider position to current slide
_.slide(0);

jedrzejchalubek avatar Nov 28 '13 07:11 jedrzejchalubek

thank you for your support, but I can't get it right: diegelernten.de#referenzen

sorsenne avatar Dec 01 '13 22:12 sorsenne

You have added paddings to '.slide', so width of each slide is higher than slider wrapper. After resize, script include all paddings into final width.

You should add next wapper inside each slide and onlyhis padding.

jedrzejchalubek avatar Dec 02 '13 07:12 jedrzejchalubek