简单JS切换代码简化

下面是是自己写的日常普通切换动作,不知道怎么去简化,看着好冗余... 譬如怎么合并prevnext两个事件?委托于control-wrap父元素上?

Live Demo

HTML

<div class="container">
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <div class="box">4</div>
    <div class="box">5</div>
    <div class="box">6</div>
    <div class="box">7</div>
    <div class="box">8</div>
    <div class="box">9</div>
</div>
<div class="control-wrap">
    <span class="prev">prev</span>
    <span class="next">next</span>
</div>

JS

https://img1.mukewang.com/5bd43209000125f604730473.jpg

慕婉清6462132
浏览 710回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript