Dan*_*Dan 3 javascript css jquery swiper
我正在使用 swiper.js ( http://idangero.us/swiper/api/#.WCBYcxKLTfA )
请在附件中找到我当前代码的工作代码:https : //jsfiddle.net/0L2h1p25/12/
我现在正试图按照我想要的方式设计它,但我需要解决两个问题。
第 1 部分:分页点不可点击 第 2 部分:导航不起作用
第 1 部分:我已经更改了 swiper.js 中的分页以获得我想要的样式,现在它阻止了用户点击点进入幻灯片。
你应该使用:
paginationClickable: true,
Run Code Online (Sandbox Code Playgroud)
允许点击,但在您使用时不起作用;
paginationType: "custom",
Run Code Online (Sandbox Code Playgroud)
我需要帮助使以下代码可点击,以便当有人点击该点时,它会转到幻灯片。
这是 swiper 执行:
// Swiper Execution
var swiper = new Swiper('.hero-container', {
direction: 'horizontal',
pagination: '.cd-slider',
nextButton: '.swiper-next',
prevButton: '.swiper-prev',
slidesPerView: 1,
paginationClickable: true,
spaceBetween: 0,
loop: true,
speed: 400,
effect: 'slide',
keyboardControl: true,
hashnav: true,
useCSS3Transforms: false,
paginationType: "custom",
paginationCustomRender: function(swiper, current, total) {
var names = [];
$(".swiper-wrapper .swiper-slide").each(function(i) {
names.push($(this).data("name"));
});
var text = "<ul>";
for (let i = 1; i <= total; i++) {
if (current == i) {
text += "<li><a class='active'><span class='cd-dot'></span><span class='cd-label'>Item 1</span></a></li>";
} else {
text += "<li><a><span class='cd-dot'></span><span class='cd-label'></span></a></li>";
}
}
text += "</ul>";
return text;
}
});
Run Code Online (Sandbox Code Playgroud)
如果我将执行更改为以下内容,则这些点是可点击的,但我无法按照我想要的方式对其进行样式设置
// Swiper Execution
var swiper = new Swiper('.hero-container', {
direction: 'horizontal',
pagination: '.cd-slider',
nextButton: '.swiper-next',
prevButton: '.swiper-prev',
slidesPerView: 1,
paginationClickable: true,
spaceBetween: 0,
loop: true,
speed: 400,
effect: 'slide',
keyboardControl: true,
hashnav: true,
useCSS3Transforms: false,
});
Run Code Online (Sandbox Code Playgroud)
第 2 部分:最后我想创建一个导航栏,以便当用户单击链接时,它会转到幻灯片,我目前没有这方面的代码,但我希望第 1 部分应该对此有所帮助。
谢谢
小智 6
您必须使用以下代码。
new Swiper('.swiper', {
pagination: {
el: '.pagination',
clickable: true,
renderBullet: function (index, className) {
return `<span class="dot swiper-pagination-bullet">${index}</span>`;
},
},
});
Run Code Online (Sandbox Code Playgroud)