| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
- ul {
- list-style: none;
- }
- #container {
- width: 590px;
- height: 470px;
- margin: 100px auto;
- position: relative;
- }
- #img-box img {
- position: absolute;
- opacity: 0;
- transition: opacity 1s linear;
- }
- #img-box .selected {
- opacity: 1;
- }
- #btns li {
- width: 20px;
- height: 20px;
- background: purple;
- color: white;
- text-align: center;
- line-height: 20px;
- border-radius: 10px;
- margin-right: 5px;
- float: left;
- }
- #btns {
- position: absolute;
- right: 10px;
- bottom: 10px;
- }
- #btns .select {
- background: red;
- }
- </style>
- </head>
- <body>
- <div id="container">
- <div id="img-box">
- <img class="selected" src="image/1.jpg" alt="">
- <img src="image/2.jpg" alt="">
- <img src="image/3.jpg" alt="">
- <img src="image/4.jpg" alt="">
- <img src="image/5.jpg" alt="">
- </div>
- <ul id="btns">
- <li class="select">1</li>
- <li>2</li>
- <li>3</li>
- <li>4</li>
- <li>5</li>
- </ul>
- <script>
- var btns = document.getElementsByTagName('li')
- var imgs = document.getElementsByTagName('img')
- for (var i = 0; i < btns.length; i++) {
- btns[i].index = i
- btns[i].onclick = function () {
- for (var j = 0; j < btns.length; j++) {
- btns[j].className = ''
- imgs[j].className = ''
- }
- this.className = 'select'
- imgs[this.index].className = 'selected'
- }
- }
- </script>
- </div>
- </body>
- </html>
|