使用之前的&部分从元素滚动下一个按钮

时间:2015-08-04 17:32:45

标签: jquery

有3个复选框。如果用户选择所有复选框,它应该跳转/滚动到循环中所有类的最近元素。如果用户只选择一个复选框,则它应该仅在循环中选定的类中跳转/滚动。

要显示当前位置,我想添加“selectedAnnotation”类

这是我的小提琴(起点):jsFiddle

谢谢你的提问。做这个的最好方式是什么? .find,.closest?

HTML

<div class="checkbox">
    <label>
        <input type="checkbox" class="version1" checked>Version I</label>
</div>
<div class="checkbox">
    <label>
        <input type="checkbox" class="version2" checked>Version II</label>
</div>
<div class="checkbox">
    <label>
        <input type="checkbox" class="version2" checked>Version III</label>
</div>
<button type="button" class="btn btn-sm btn-default start">Start</button>
<button type="button" class="btn btn-sm btn-default pre">   <span class="fa fa-chevron-left"></span> Previous</button>
<button type="button" style="width: 80px;" class="btn btn-sm btn-default nex">Next <span class="fa fa-chevron-right"></span>

</button>
<p id="resultText">Contrary to popular belief, <span class="v1 firstelement selectedAnnotation">Lorem Ipsum</span> is not simply random text. It has roots in a piece of <span class="v3">classical </span> Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor <span class="v2">at Hampden-Sydney</span> College in Virginia, looked up one of the more obscure <span class="v1">Latins</span>, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. <span class="v3">Lorem </span>Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum <span class="v2">ete</span> Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de <span class="v1">Finibus</span> et Malorum" by Cicero are also reproduced in <span class="v2">their</span> exact original form, accompanied by English versions from the 1914 translation by H. <span class="v1">Rackam</span>.</p>

JS

$(".start").click(function () {

    if ($('.firstelement').hasClass('selectedAnnotation')) {
        $('.firstelement').removeClass('selectedAnnotation');
        } else {
        $('.firstelement').addClass('selectedAnnotation');
        }
});


$(".pre").click(function() {    

});

$(".nex").click(function() {    

}); 

0 个答案:

没有答案