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 73 74 75 76 77 78 79 80 81 82 83
| <!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> .tip-bar { display: inline-flex; align-items: center; height: 30px; background-color: rgba(0,0,0,.4); border-radius: 16px; } img { width: 30px; height: 30px; border-radius: 50%; margin-right: 5px; } span { font-size: 13px; color: white; margin-right: 8px; } </style> </head> <body> <div class="tip-bar"> <img src="https://bfs.biyao.com/group1/M01/A2/67/rBACVGA_iOuAYaTxAAAPbted3yE165.png" alt=""> <span>183***138对这件商品感兴趣</span> </div>
<script> let tipList = [ { icon: 'https://bfs.biyao.com/group1/M01/A6/97/rBACYWBCHqyAFH5tAAANZXX5Eww646.png', title: 'coderwhy对这件商品感兴趣' }, { icon: 'https://bfs.biyao.com/group1/M01/A2/67/rBACVGA_iOuAYaTxAAAPbted3yE165.png', title: '123***814对这件商品感兴趣' }, { icon: 'https://bfs.biyao.com/group1/M00/7F/4E/rBACYV16HseAP-PnAAAW9bbVoKE463.png', title: '刘军对这件商品感兴趣' } ]
var tipBar = document.querySelector(".tip-bar") var imgEl = tipBar.querySelector("img") var spanEl = tipBar.querySelector("span")
var currentIndex = 0 setInterval(function() { var tipItem = tipList[currentIndex]
imgEl.src = tipItem.icon spanEl.textContent = tipItem.title currentIndex++ if (currentIndex === tipList.length) { currentIndex = 0 } }, 3000)
</script>
</body> </html>
|