上面引入的三个文件中, 有一个叫做/danmu/index.js的文件需要我们自己编写和创建的:
在根目录的source文件夹下创建danmu/index.js文件:
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 84 85 86
|
function renderData() { let homeDanmuArr = [ { img: "http://120.48.121.186/medias/logo.png", info: "欢迎访问bamboo主题", href: "https://yuang01.github.io/", close: true, speed: 15, color: "#42b983", old_ie_color: "#000000", }, { img: "http://120.48.121.186/medias/logo.png", info: "国内可以访问http://120.48.121.186", href: "http://120.48.121.186", close: true, speed: 15, color: "blue", old_ie_color: "#000000", }, { img: "http://120.48.121.186/medias/logo.png", info: "国内可以访问http://120.48.121.186", href: "http://120.48.121.186", close: true, speed: 12, color: "red", old_ie_color: "#000000", }, ]; for (var i = 0; i < 20; i++) { homeDanmuArr[i] = homeDanmuArr[i] ? homeDanmuArr[i] : {speed: 12}; } return homeDanmuArr; } function homeDanmuFn() { let data = renderData(); let homelooper_time = 3 * 1000; let items = data; let total = data.length; let run_once = true; let index = 0; barrager(); async function barrager() { if (run_once) { homelooper = setInterval(barrager, homelooper_time); run_once = false; } const responseImg = await fetch('https://api.btstu.cn/sjtx/api.php?lx=c1&format=json'); const imgJson = await responseImg.json(); const responseInfo = await fetch('https://api.vvhan.com/api/ian?type=json'); const infoJson = await responseInfo.json(); items[index].img = imgJson.imgurl; index > 2 && (items[index].info = infoJson.ishan); $("body").barrager(items[index]); index++; if (index == total) { clearInterval(homelooper); return false; } } } homeDanmuFn();
document.addEventListener('pjax:send', function (e) { if (homelooper) { clearInterval(homelooper); $.fn.barrager.removeAll(); } })
|