0

I was wondering if it is possible to give the flexslider a minimum height (sure it can), but that the images of the slider will overflow by the viewport at both sides, left and right, so the middle of the image will be centered in the middle of the viewport. Like with the trick of margin-left: -width.

I use the basic markup of the flexslider:

<section class="slider">
            <div class="flexslider">
                <ul class="slides">
                    <li>
                        <img src="images/slide2.jpg" />
                    </li>
                    <li>
                        <img src="images/slide2.jpg" />
                    </li>
                    <li>
                        <img src="images/slide2.jpg" />
                    </li>
                    <li>
                        <img src="images/slide2.jpg" />
                    </li>
                </ul>
            </div>
        </section>

Than I added the start and before to the slider plugin:

$('.flexslider').flexslider({
        animation: "slide",
        slideshowSpeed: 5000,
        manualControls: ".custom-controls li",
        directionNav: false,
        useCSS: false, /* Chrome fix*/
        start: function(slider){
            $('body').removeClass('loading');

            $('.flexslider').css({
                position:'absolute',
                left: ($(window).width() - $('.flexslider').outerWidth())/2,
                top: ($(window).height() - $('.flexslider').outerHeight())/2
            });
        },
        before: function(slider) {
            $('.flexslider').css({
                position:'absolute',
                left: ($(window).width() - $('.flexslider').outerWidth())/2,
                top: ($(window).height() - $('.flexslider').outerHeight())/2
            });
        }
    });

But this is not working for me. I don't think I get the right elements here.. Tried also $('.flexslider .slides li img') but nothing seems to work of these selectors. Only the top property in above code is working.

Thanks in advance.

0

1 Answer 1

1

you can use the following css:

.flexslider {
   position:fixed;
   left:50%;
   top:50%;
   transform: translate(-50%, -50%);
}

Example

7
  • Sorry, I just change the answer and added an example, you'll need to remove the before and start functions that change the css and add the above styles to your css file (after the flexslider style sheet)
    – Pete
    Jul 29, 2015 at 10:00
  • I was just about to add a comment saying, it's probably best to add these styles to your container rather than the flexslider itself: codepen.io/anon/pen/KpryOE
    – Pete
    Jul 29, 2015 at 10:10
  • Ah great, but now the slider is position at the bottom right... And not in the center of the viewport.
    – Caspert
    Jul 29, 2015 at 10:12
  • Which version of safari and ios are you using as it should work: caniuse.com/#search=translate
    – Pete
    Jul 29, 2015 at 11:10
  • 1
    I have the latest version. It works well, just forget the prefixes! Thanks for the answer!
    – Caspert
    Jul 29, 2015 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.