经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » JavaScript » 查看文章
vue中使用swiper并自定义分页器样式
来源:cnblogs  作者:Nicederen  时间:2019/3/29 15:09:46  对本文有异议

一,安装swiper

执行命令 npm install --save swiper

二,引入swiper

import Swiper from "swiper";
import "swiper/dist/css/swiper.css";
 
三,使用swiper,不废话,上代码。
  1. <template>
  2. <div class="page">
  3. <div class="swiper-container">
  4. <div class="swiper-wrapper">
  5. <div class="swiper-slide">
  6. <img class="imgCard" src="../assets/swiper1.jpg" alt>
  7. </div>
  8. <div class="swiper-slide">
  9. <img class="imgCard" src="../assets/swiper2.jpg" alt>
  10. </div>
  11. <div class="swiper-slide">
  12. <img class="imgCard" src="../assets/swiper3.jpg" alt>
  13. </div>
  14. </div>
  15. <div class="swiper-pagination"></div>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import Swiper from "swiper";
  21. import "swiper/dist/css/swiper.css";
  22. export default {
  23. data() {
  24. return {
  25. dialogShow: false
  26. };
  27. },
  28. mounted() {
  29. this._initSwiper();
  30. },
  31. methods: {
  32. _initSwiper() {
  33. var mySwiper = new Swiper(".swiper-container", {
  34. direction: "horizontal",
  35. loop: true,
  36. autoplay: true, //自动轮播
  37. speed: 1000,
  38. pagination: {
  39. el: ".swiper-pagination",
  40. type: "custom",
  41. renderCustom: function(swiper, current, total) {
  42. var customPaginationHtml = "";
  43. for (var i = 0; i < total; i++) {
  44. //判断哪个分页器此刻应该被激活
  45. if (i == current - 1) {
  46. customPaginationHtml +=
  47. '<span class="swiper-pagination-customs swiper-pagination-customs-active"></span>';
  48. } else {
  49. customPaginationHtml +=
  50. '<span class="swiper-pagination-customs"></span>';
  51. }
  52. }
  53. return '<span class="swiperPag">'+customPaginationHtml+'</span>';
  54. }
  55. }
  56. });
  57. }
  58. }
  59. };
  60. </script>
  61. <style lang="scss" >
  62. .swiperPag {
  63. width:4.5rem;
  64. height: 0.07rem;
  65. border-radius: 0.04rem;
  66. display: flex;
  67. align-items: center;
  68. margin:0 auto;
  69. background-color: rgba($color: #000000, $alpha: 0.8)
  70. }
  71. .swiper-pagination-fraction, .swiper-pagination-custom, .swiper-container-horizontal > .swiper-pagination-bullets {
  72. bottom:0.27rem;
  73. }
  74. .swiper-pagination-customs {
  75. width: 1.5rem;
  76. height: 0.14rem;
  77. display: inline-block;
  78. }
  79. /*自定义分页器激活时的样式表现*/
  80. .swiper-pagination-customs-active {
  81. width: 1.5rem;
  82. height: 0.14rem;
  83. display: inline-block;
  84. border-radius: 0.07rem;
  85. background-color: #28a7e1;
  86. }
  87. </style>

注意: style标签不要加scoped,否则样式加不上!

原文链接:http://www.cnblogs.com/nicederen/p/10620534.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号