广告位联系
返回顶部
分享到

swiper中swiper-pagination中的位置设置方法

css 来源:互联网 作者:佚名 发布时间:2024-06-24 23:20:11 人浏览
摘要

需求: 期望swiper-pagination 导航靠右下角 解决: 可以配置clickableClass这个属性,属性值指定的是你自定义的class类名。 swiper实例,导航paination,添加clickableCalss属性: 1 2 3 4 5 6 7 var mySwiper = new

需求:

期望swiper-pagination 导航靠右下角 

解决:

可以配置clickableClass这个属性,属性值指定的是你自定义的class类名。
swiper实例,导航paination,添加clickableCalss属性:

1

2

3

4

5

6

7

var mySwiper = new Swiper('.swiper-container',{

  pagination:{

    el: '.swiper-pagination',

    clickable: true,

    clickableClass : 'my-pagination-clickable',

  },

})

然后在css中定义.my-pagination-clickable。

1

2

3

4

5

/*增加自定义css class*/

        .swiper .my-pagination-clickable {

            width: 1200px;

            text-align: right;

        }

     根据我的期望效果是让导航靠右下角。原css配置样式写死了left:0,所有只要把left:0冲掉,然后让导航在右边就可。

最终实现的效果:

 html完整源码:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="utf-8"/>

    <title>Swiper demo</title>

    <meta

            name="viewport"

            content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"

    />

    <!-- Link Swiper's CSS -->

    <link rel="stylesheet" href="swiper-bundle.min.css">

    <!-- Demo styles -->

    <style>

        html,

        body {

            position: relative;

            height: 100%;

        }

        body {

            background: #eee;

            font-family: Helvetica Neue, Helvetica, Arial, sans-serif;

            font-size: 14px;

            color: #000;

            margin: 0;

            padding: 0;

        }

        .swiper {

            width: 1226px;

            height: 460px;

        }

        .swiper-slide {

            text-align: center;

            font-size: 18px;

            background: #fff;

            /* Center slide text vertically */

            display: -webkit-box;

            display: -ms-flexbox;

            display: -webkit-flex;

            display: flex;

            -webkit-box-pack: center;

            -ms-flex-pack: center;

            -webkit-justify-content: center;

            justify-content: center;

            -webkit-box-align: center;

            -ms-flex-align: center;

            -webkit-align-items: center;

            align-items: center;

        }

        .swiper-slide img {

            display: block;

            width: 100%;

            height: 100%;

            object-fit: cover;

        }

        /*增加自定义css class*/

        .swiper .my-pagination-clickable {

            width: 1200px;

            text-align: right;

        }

    </style>

</head>

<body>

<!-- Swiper -->

<div class="swiper mySwiper">

    <div class="swiper-wrapper">

        <div class="swiper-slide">Slide 1</div>

        <div class="swiper-slide">Slide 2</div>

        <div class="swiper-slide">Slide 3</div>

        <div class="swiper-slide">Slide 4</div>

        <div class="swiper-slide">Slide 5</div>

    </div>

    <div class="swiper-button-next"></div>

    <div class="swiper-button-prev"></div>

    <div class="swiper-pagination"></div>

</div>

<!-- Swiper JS -->

<script src="swiper-bundle.min.js"></script>

<!-- Initialize Swiper -->

<script>

    //    初始化轮播图

    let swiper = new Swiper(".mySwiper", {

        spaceBetween: 30,

        centeredSlides: true,

        autoplay: {

            delay: 2500,

            disableOnInteraction: false,

        },

        navigation: {

            nextEl: ".swiper-button-next",

            prevEl: ".swiper-button-prev",

        },

        pagination: {

            el: ".swiper-pagination",

            clickable: true,

            clickableClass: 'my-pagination-clickable'

        },

    });

</script>

</body>

</html>

页面刷新导航栏漂移问题

可以参考以下配置试试

1

2

3

4

5

6

7

/*增加自定义css class*/

.swiper .my-pagination-clickable {

width: auto;

bottom: 26px;

right: 30px;

text-align: right;

}


版权声明 : 本文内容来源于互联网或用户自行发布贡献,该文观点仅代表原作者本人。本站仅提供信息存储空间服务和不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权, 违法违规的内容, 请发送邮件至2530232025#qq.cn(#换@)举报,一经查实,本站将立刻删除。

您可能感兴趣的文章 :

原文链接 :
相关文章
  • 本站所有内容来源于互联网或用户自行发布,本站仅提供信息存储空间服务,不拥有版权,不承担法律责任。如有侵犯您的权益,请您联系站长处理!
  • Copyright © 2017-2022 F11.CN All Rights Reserved. F11站长开发者网 版权所有 | 苏ICP备2022031554号-1 | 51LA统计