Angel丶守护&雪之源 2023-04-19 10:54 采纳率: 22%
浏览 14
已结题

swiper设置了spaceBetween后无法显示箭头,单独使用重写的组件却没有问题

PHP部分代码:

echo do_shortcode([
            'code'    => 'postslider',
            'options' => [
                "source"                    => "product",                                                               //数据类型
                "count"                     => vc_get_theme_option('product-swiper-count', 12),                         //请求条数
                "category"                  => $term_ids,                                                               //分类
                "order"                     => "DESC",                                                                  //排序
                "loop"                      => vc_get_theme_option('product-swiper-loop', "no"),                        //无缝连接
                "title-align"               => vc_get_theme_option('product-swiper-title-align', "left"),               //标题对齐
                "title-location"            => vc_get_theme_option('product-swiper-title-location', "static"),          //标题位置
                "title-line-count"          => vc_get_theme_option('product-swiper-title-line-count', 2),               //标题行数
                "img-hover"                 => vc_get_theme_option('product-swiper-img-hover', "no"),                   //触摸变大
                "title-bgcolor"             => vc_get_theme_option('product-swiper-title-bgcolor', "#fff"),             //标题遮盖层背景颜色
                "image-style-enable"        => vc_get_theme_option('product-swiper-image-style-enable', "no"),          //启用图片样式
                "image-height"              => vc_get_theme_option('product-swiper-image-height', "auto"),              //图片高度
                "mobile-image-height"       => vc_get_theme_option('product-swiper-mobile-image-height', "auto"),       //小屏图片高度
                "image-size"                => vc_get_theme_option('product-swiper-image-size', "contain"),             //图片尺寸
                "title-font-enable"         => vc_get_theme_option('product-swiper-title-font-enable', "no"),           //启用标题样式
                "title-font"                => vc_get_theme_option('product-swiper-title-font', []),                    //标题样式
                "title-font-hover-enable"   => vc_get_theme_option('product-swiper-title-font-hover-enable', "no"),     //启用标题悬浮样式
                "title-font-hover"          => vc_get_theme_option('product-swiper-title-font-hover', []),              //标题悬浮样式
                "effect"                    => vc_get_theme_option('product-swiper-effect', "slide"),                   //切换方式
                "speed"                     => vc_get_theme_option('product-swiper-speed', 6),                          //灯片切换时长
                "perview"                   => vc_get_theme_option('product-swiper-perview', 3),                        //显示数量
                "mobile-count"              => vc_get_theme_option('product-swiper-mobile-count', 3),                   //移动端显示数量
                "spaceBetween"              => vc_get_theme_option('product-swiper-spaceBetween', 10),                  //间距
                "arrow"                     => vc_get_theme_option('product-swiper-arrow', "yes"),                      //显示箭头
                "arrowColor"                => vc_get_theme_option('product-swiper-arrowColor', ""),                    //箭头颜色
                "arrow-size"                => vc_get_theme_option('product-swiper-arrow-size', "44px"),                //箭头大小
                "pagination"                => "no",                                                                    //显示分页器
                "autoplay"                  => vc_get_theme_option('product-swiper-autoplay', 1),                       //自由切换时长
            ]
        ]);

js部分代码:

parseOpts() {
return {
// 跑马灯灯片滑动时间
speed: this.parseMarquee(this.$opts.speed),
// 当开启跑马灯时,autoplay为灯片停顿时间,关闭跑马灯时为轮播图切换下一张图片的等待时间
autoplay: this.parseAutoplay(this.$opts.autoplay),
// 当开启跑马灯效果时,默认开启无缝链接
loop: this.$opts.loop === 'yes' || this.$opts.effect == 'marquee' ? true : false,
// 灯片之间的间距
spaceBetween: this.$opts.spaceBetween || 0,
// 是否允许鼠标滚轮切换灯片
mousewheel: this.$opts.mousewheel === 'yes',
// 是否允许键盘左右键切换灯片
keyboard: this.$opts.keyboard === 'yes',
// 轮播图切换灯片方式
effect: this.$opts.effect,
// 轮播容器能存放灯片张数
slidesPerView: this.$opts['mobile-count'] != 0 ? this.$opts['mobile-count'] : this.$opts.perview,
// 轮播图方向
direction: 'horizontal',
// 当没有足够的slide切换时,swiper失效且隐藏导航等。
watchOverflow: true,
// 更改swiper 的样式(如隐藏/显示)或修改其子元素(如添加/删除幻灯片),每次 Swiper 都会更新(重新初始化),开启跑马灯时不更新。
observer: this.$opts.effect !== 'marquee',
// 当Swiper的祖先元素变化时,Swiper更新,开启跑马灯时不更新
observeParents: this.$opts.effect !== 'marquee',
// 子slide更新时,swiper更新,开启跑马灯时不更新
observeSlideChildren: this.$opts.effect !== 'marquee',
// 轮播断点设定,允许为不同的响应断点(屏幕尺寸)设置不同的参数。
breakpoints: {
768: {
slidesPerView: this.$opts.perview,
}
},
// 上下切换按钮
navigation: {
nextEl: '.swiper-button-next__' + this.id,
prevEl: '.swiper-button-prev__' + this.id,
},
// 分页器按钮
pagination: {
el: '.swiper-pagination__' + this.id,
clickable: true,
type: this.parsePagination(this.$opts.paginationType)
},
// 是否开启淡入淡出效果
fadeEffect: {
crossFade: true,
}
}
},

现在注释spaceBetween后显示正常也可以自由切换幻灯片,如图所示:

img

没注释的情况下,箭头被元素被添加类名swiper-button-lock,设置为none,如图所示:

img

但是正常使用重写的组件时却没有问题,设置都是一样的,如图所示:

img

不知道问题出在哪里了,望解答一下!

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-04-20 16:37
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:
    • 以下回答来自chatgpt: 很可能是你的CSS样式和JS代码出现了冲突或者问题。以下是几个可能的解决方案: 1. 检查CSS样式中是否对.swiper-button-lock样式设置了display: none属性。如果有的话,请将这个属性去掉。 2. 在JS初始化Swiper的时候,尝试使用以下语句来禁用按键锁定功能: ``` swiper.on('init', function() { swiper.lockSwipeToNext(); }); ``` 这将禁用Swiper的按键锁定功能,并且应该可以解决箭头无法显示的问题。 3. 检查JS代码中是否有其他的事件处理程序在执行锁定按键功能。如果是,请考虑禁用这个事件处理程序,以解决此问题。 4. 最简单的方法是在Swiper的相关文档中查找是否有其他类似的问题出现,并参考相关的解决方案。 希望这些解决方案可以帮助到你解决问题!

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月14日
  • 创建了问题 4月19日

悬赏问题

  • ¥20 python爬虫遇到空文本取不出来
  • ¥15 x264库中预测模式字IPM、运动向量差MVD、量化后的DCT系数的位置
  • ¥15 curl 命令调用正常,程序调用报 java.net.ConnectException: connection refused
  • ¥20 关于web前端如何播放二次加密m3u8视频的问题
  • ¥15 使用百度地图api 位置函数报错?
  • ¥15 metamask如何添加TRON自定义网络
  • ¥66 关于川崎机器人调速问题
  • ¥15 winFrom界面无法打开
  • ¥30 crossover21 ARM64版本安装软件问题
  • ¥15 mymetaobjecthandler没有进入