我使用下面的 javaScript 来控制下一个和上一个事件。
JS:
var nextprev=setting.nextprev
if (typeof toc=="string" && toc!="markup" || typeof toc=="object"){
for (var i=1; i<=setting.contentdivs.length; i++){
phtml+='<a href="#'+i+'" class="toc">'+(typeof toc=="string"? toc.replace(/#increment/, i) : toc[i-1])+'</a> '
}
phtml=(nextprev[0]!=''? '<a href="#prev" class="prev">'+nextprev[0]+'</a> ' : '') + phtml + (nextprev[1]!=''? '<a href="#next" class="next">'+nextprev[1]+'</a>' : '')
pdiv.innerHTML=phtml
}
HTML 中包含的脚本如下。
featuredcontentslider.init({
id: "slider1", //id of main slider DIV
contentsource: ["inline", ""], //Valid values: ["inline", ""] or ["ajax", "path_to_file"]
toc: " ", //Valid values: "#increment", "markup", ["label1", "label2", etc]
nextprev: [" ", " "], //labels for "prev" and "next" links. Set to "" to hide.
revealtype: "click", //Behavior of pagination links to reveal the slides: "click" or "mouseover"
enablefade: [false], //[true/false, fadedegree]
autorotate: [false], //[true/false, pausetime]
onChange: function(previndex, curindex, contentdivs){ //event handler fired whenever script changes slide
//previndex holds index of last slide viewed before current (0=1st slide, 1=2nd etc)
//curindex holds index of currently shown slide (0=1st slide, 1=2nd etc)
}
})
下一个和上一个工作正常,但我需要将下一个和上一个卡住到它们的位置,即首先是前一个,最后是下一个。我不太确定该怎么做。
我所说的卡住是指以下内容。
目前,当您按上一个或下一个时,它们会移动到 1,2,3,1.. 等等 .. 我希望它们在最后被锁定。例如,如果我的页面加载时间为 1,那么当我按下一步时,它应该是 1,2,3 就是这样。最后应该停止了。当我从 3,2,1 按上一个时,它应该停在 1,而不是转到 3,2,1,3.. 等等。希望这有帮助
您可以从下面的 jsFiddle 链接查看工作演示。
<强> WORKING DEMO
最佳答案
参见http://jsfiddle.net/4xvcuz6h/6/
if (turntopage == 1){
document.getElementsByClassName("prev")[0].removeAttribute("href");
}
else{
document.getElementsByClassName("prev")[0].href = "#prev";
}
if (turntopage == totalpages){
document.getElementsByClassName("next")[0].removeAttribute("href");
}
else{
document.getElementsByClassName("next")[0].href = "#next";
}
和
pdivlinks[i].onclick=function(){
if (this.href){ //only handle when href is set
featuredcontentslider.turnpage(setting, this.className)
return false
}
}
关于javascript - 卡住下一个和上一个事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30301514/