Carousel bootstrap 4 only in mobile mode

Asked

Viewed 1,400 times

2

Given the image below that represents desktop mode, I would like to know how to turn a Carousel only in mobile mode.

quero que esses items no modo mobile vire um carousel,mas quando visualizar a tela no modo desktop fique deste jeito como da imagem

!--- Team ----->


<div id="team" class="team">
    <div class="container">
        <div class="row">
            <h2 class="wow fadeInUp">Meet our team</h2>
            <p class="wow fadeInUp" data-wow-delay="0.4">Lorem Ipsum passages, and more recently with desktop publishing software</p>
            <div class="col-lg-3 col-md-3 wow fadeInLeft" data-wow-delay="2s">
                <img src="images/team/team-1.jpg" class="img-circle" alt="">
                <h4>John Doe</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
            <div class="col-lg-3 col-md-3  wow fadeInLeft"  data-wow-delay="1.6s">
                <img src="images/team/team-2.jpg" class="img-circle" alt="">
                <h4>John Doe</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
            <div class="col-lg-3 col-md-3  wow fadeInLeft"  data-wow-delay="1.2s">
                <img src="images/team/team-3.jpg" class="img-circle" alt="">
                <h4>John Doe</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
            <div class="col-lg-3 col-md-3  wow fadeInLeft" 0.8>
                <img src="images/team/team-4.jpg" class="img-circle" alt="">
                <h4>John Doe</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
        </div>
    </div>
</div>

<!--- End Team ---->
  • And your question is?

  • how do I do?

  • How does what?

  • given the image, I would like in mobile mode(only) they are displayed in Carousel format

  • Put the relevant rest of your code, the posted does not reflect the example image. Nor the current scenario where the problem occurs.

  • The Carousel is working?

  • Yes, I just wanted to check if mobile mode then yes enable the Carousel

  • Just add the data-ride="Carousel" attribute to @mediaquery for mobile. But for a more detailed example, put your html code and js here to check the behavior and fix

  • I put the code that is html, ai type, has this template with Controls:https://v4-alpha.getbootstrap.com/components/carousel/ like to make it appear only on mobile, type I can add this attribute data-ride="Carousel" in <div id="team" class="team"> ?

Show 4 more comments

1 answer

2


I made this template with just a few lines of CSS. The idea is to leave the "component" of the static team only on large screens, and on small screens I give a display:none in it while I give a display:block in the Slider. So with this option you have two "components" ok.

See Example working: (when the screen is less than 790px it will show the Slider, but if it is bigger it shows the static list.) Click "Whole Page" for slider disappear and he’s static.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name=
 content=
>
    <title>Page Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous" />
    <link rel="stylesheet" type="text/css" media="screen" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<style>
    .carousel {
        display: none;
    }
    @media (max-width: 790px) {
        .carousel {
            display: block;
            text-align: center;
        }
        .team {
            display: none;
        }
    }
</style>
</head>
<body>
    
    <h2 class="wow fadeInUp">Meet our team</h2>
    <p class="wow fadeInUp" data-wow-delay="0.4">Lorem Ipsum passages, and more recently with desktop publishing software</p>
    <div id="team" class="team">
        <div class="container">
            <div class="row">
                <div class="col-lg-3 col-md-3 wow fadeInLeft" data-wow-delay="2s">
                    <img src="http://placecage.com/150/150" class="img-circle" alt="">
                    <h4>John Doe</h4>
                    <b>CEO and Founder</b>
                    <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                    <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
                </div>
                <div class="col-lg-3 col-md-3  wow fadeInLeft"  data-wow-delay="1.6s">
                    <img src="http://placecage.com/150/150" class="img-circle" alt="">
                    <h4>John Doe</h4>
                    <b>CEO and Founder</b>
                    <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                    <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
                </div>
                <div class="col-lg-3 col-md-3  wow fadeInLeft"  data-wow-delay="1.2s">
                    <img src="http://placecage.com/150/150" class="img-circle" alt="">
                    <h4>John Doe</h4>
                    <b>CEO and Founder</b>
                    <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                    <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
                </div>
                <div class="col-lg-3 col-md-3  wow fadeInLeft" 0.8>
                    <img src="http://placecage.com/150/150" class="img-circle" alt="">
                    <h4>John Doe</h4>
                    <b>CEO and Founder</b>
                    <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                    <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                    <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
                </div>
            </div>
        </div>
    </div>
<br>
<br>
<br>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div class="carousel-inner" role="listbox">
          <div class="carousel-item active">
            <div class="col-lg-12 wow fadeInLeft" 0.8>
                <img src="http://placecage.com/150/150" class="img-circle" alt="">
                <h4>John Doe</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
          </div>
          <div class="carousel-item">
            <div class="col-lg-12 wow fadeInLeft" 0.8>
                <img src="http://placecage.com/150/150" class="img-circle" alt="">
                <h4>John Doe 2</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
          </div>
          <div class="carousel-item">
            <div class="col-lg-12 wow fadeInLeft" 0.8>
                <img src="http://placecage.com/150/150" class="img-circle" alt="">
                <h4>John Doe 3</h4>
                <b>CEO and Founder</b>
                <p>Lorem Ipsum passages, and more recently with desktop publishing software</p>
                <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>
                <a href="#"><i class="fa fa-pinterest" aria-hidden="true"></i></a>
            </div>
          </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    
    
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.bundle.min.js"></script>

    <script>
    $('.carousel').carousel({
        interval: 500
    })
    </script>
</body>
</html>

OBS1: to control the screen width where the Slider appears configure here

@media (max-width: 790px) { /* largura que vc quer que apareça */
    .carousel {
        display: block;
        text-align: center;
    }
    etc.....
}

OBS2: Here you control the speed of the Slider

$('.carousel').carousel({
    interval: 500 /* quanto maior o número mais devagar a transição */
})
  • Thank you so much! <3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.