我的代码大致如下
//css
li{display:inline-block}
//html #li margin and width are dynamic
<ul>
<li style= margin:30px;width:100px; >Pic</li>
<li style= margin:40px;width:200px; >Pic</li>
<li style= margin:10px;width:500px; >Pic</li>
<li style= margin:50px;width:300px; >Pic</li>
</ul>
如何制作一个jQuery函数,它将以li索引作为输入,并返回从开始到该索引的所有li的宽度+边距左+右。
Examples // something like this
myFunction(1); //output 440 (( 30 margin-left [0] + 30 margin-right [0] + 40 margin-left [1] + 40 margin-right [1] + 100 width [0] + 200 width [1] ))
myFunction(2); //output 960 (( 30 margin-left [0] + 30 margin-right [0] + 40 margin-left [1] + 40 margin-right [1] + 10 margin-left [2] + 10 margin-right [2] + 100 width [0] + 200 width [1] + 500 width [2] ))