malsup / cycle2

2nd gen cycling
899 stars 238 forks source link

Center Plugin with nested slide show adds margins to inner slides #757

Open javeednizami opened 8 years ago

javeednizami commented 8 years ago

This issue is for the usecase where a slide in the cycle has an inner slide how. When using the center plugin the slides from inner slide show also get margins added to the outer slideshow's slides causing the inner slides to lose proper positioning. Ideally we should be able to explicitly control each slide show to be centered or not in its parent container. Or only center the outer slides and leave the inner slides alone.

I had to workaround (hack) by adding a class "inner-slideshow" to the slide container and changing the adjustSlide function to skip slides from the inner slideshow.

 function adjustSlide() {
        /*jshint validthis: true */
        var slide = $(this);
        var contW = opts.container.width();
        var contH = opts.container.height();
        var w = slide.outerWidth();
        var h = slide.outerHeight();
        if (w **&& slide.parent().hasClass('inner-slideshow')**== false) {
            if (opts.centerHorz && w <= contW)
                slide.css( 'marginLeft', (contW - w) / 2 );
            if (opts.centerVert && h <= contH)
                slide.css( 'marginTop', (contH - h) / 2 );
        }
    }