1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> *{ margin: 0; padding: 0; } ul{ width:800px; list-style: none; display: flex; margin: 30px auto; position: relative; } li{ background-color: pink; width: 80px; text-align: center; padding: 10px 0; border: 2px solid black; } div{ width: 80px; height: 5px; background-color: blue; position: absolute; bottom: 0; left: 0; transition: all .5s linear; } </style> </head> <body> <ul> <li>0</li> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <div id="slide"></div> </ul> </body> </html> <script type="text/javascript"> var liArray=document.getElementsByTagName("li"); for(var i=0;i< liArray.length; i++){ liArray[i].style.cursor="pointer"; liArray[i].onclick=function(){
var index=0; for(var j=0;j< liArray.length; j++){ if (this==liArray[j]) { index=j; } } slide.style.left=80*index+"px"; } } </script>
|