• vue 分页器组件+css动画效果


    全网都找了一遍没有找到符合UI需求的分页动画,于是就主动上手了

    需求:

    1、分页最多显示9页,总页数最多显示无上限;

    2、点击下一页的时候需要有动画效果过度,如果当前页数是当前显示最后的一页,则停了当前显示最后的位置,但是点击下一页的时候需要用户感知

    效果如图所示:

    1、代码如下:

    1. <template>
    2. <div><br>当前显示页面{{current}}
    3. <div class="pagination">
    4. <div @click="prevPage">上一页</div>
    5. <div v-for="(item, index) in totalPages" :key="index" :class="{ 'active': current == item }">
    6. <div v-if="node.indexOf(item) != -1" class="point"></div>
    7. </div>
    8. <div @click="nextPage">下一页</div>
    9. </div>
    10. </div>
    11. </template>
    12. <script>
    13. export default {
    14. name: 'Pagination',
    15. props: {
    16. totalPages: {
    17. type: Number,
    18. required: true
    19. },
    20. pageSize: {
    21. type: Number
    22. }
    23. },
    24. data() {
    25. return {
    26. current: 1, // 当前选中页
    27. node: [], // 当前显示的页数组
    28. }
    29. },
    30. methods: {
    31. prevPage() {
    32. if (this.current == 1) {
    33. return
    34. }
    35. this.current -= 1
    36. let noedeIndex = this.node[this.node.length - 1]
    37. this.$emit('pageChange', this.current)
    38. if ((noedeIndex - (this.current - 1)) > this.pageSize) {
    39. this.node.pop() // 删除最后一个
    40. this.node.unshift(this.current) // 开头插入一个
    41. }
    42. },
    43. nextPage() {
    44. if (this.current == this.totalPages) {
    45. return
    46. }
    47. this.current += 1
    48. this.$emit('pageChange', this.current)
    49. let noedeIndex = this.node[this.node.length - 1]
    50. // 当前页不等于最后一页,当前页大于等于展示页,当前页大于缓存数组的最后一页(确保重复加入)
    51. if (this.current > this.pageSize && (this.current > noedeIndex)) {
    52. this.node.shift() // 删除第一个
    53. this.node.push(this.current) // 最近最新一个
    54. }
    55. },
    56. },
    57. mounted() {
    58. for (let i = 1; i <= this.pageSize; i++) {
    59. this.node.push(i)
    60. }
    61. },
    62. }
    63. </script>
    64. <style lang="less" scoped>
    65. .pagination {
    66. display: flex;
    67. width: 100%;
    68. justify-content: center;
    69. }
    70. .point {
    71. margin: 0 5px;
    72. width: 8px;
    73. height: 8px;
    74. // margin: -5px 0 0 0;
    75. border-radius: 50%;
    76. background: #B5AC97;
    77. transition: transform 0.3s, background 0.3s;
    78. }
    79. .active .point {
    80. -webkit-transform: scale3d(1.5, 1.5, 1);
    81. transform: scale3d(1.5, 1.5, 1);
    82. // width: 10px;
    83. // height: 10px;
    84. background: #FFE6AD;
    85. box-shadow: 0 0 4px 0 #FFE990;
    86. animation: 0.3s linear 0s 1 alternate example;
    87. }
    88. @keyframes example {
    89. 0% {
    90. transform: scale3d(1, 1, 1);
    91. }
    92. 25% {
    93. transform: scale3d(1, 1, 1);
    94. }
    95. 50% {
    96. transform: scale3d(1.5, 1.5, 1);
    97. }
    98. 100% {
    99. transform: scale3d(1.5, 1.5, 1);
    100. }
    101. }
    102. </style>

    2、引用方式

    1. <template>
    2. <div>
    3. <pagination :total-pages="totalPages" :page-size="9" @pageChange="handlePageChange" />
    4. </div>
    5. </template>
    6. <script>
    7. import Pagination from './views/Pagination.vue'
    8. export default {
    9. components: {
    10. Pagination
    11. },
    12. data() {
    13. return {
    14. totalPages: 25,
    15. }
    16. },
    17. computed: {
    18. },
    19. methods: {
    20. handlePageChange(page) {
    21. console.log('page: ', page);
    22. }
    23. }
    24. }
    25. </script>

  • 相关阅读:
    istio pod不启动及访问报RBAC错误问题解决
    八股文-面向对象的理解
    数据库内容快速回顾
    Vue+elementUI 导出word打印
    SpringBoot WebService服务端&客户端使用教程
    npcap开发指南
    Python 小爬虫入门 -- 爬取专栏文章标题保存到 CSV 文件中
    Telegraf--采集指定信息
    深入探讨QUIC的工作原理,它是如何改善网络性能的?
    乐信仍面临资产质量下降和拖欠率上升风险
  • 原文地址:https://blog.csdn.net/timebeign/article/details/132710150