前言
本文操作的前置准备,需要已经搭建好自己的hexo个人博客。没有搭建博客的话,可以根据本站之前的教程文章一步一步跟着搭建。搭建好后,需要live2d小人就可以跟着本文操作
具体操作
1.拉取live2d-widget项目
前往live2d-widget,通过git clone
拉取项目到使用的主题的source文件夹下
2.使用live2d
在主题的layout文件夹内,找到head文件,并将以下代码添加其中
<script src="/live2d-widget/autoload.js"></script>
修改live2d-widget文件夹下的autoload.js
const live2d_path = "/live2d-widget/";
cdnPath: "https://npm.elemecdn.com/akilar-live2dapi@latest/",
修改后,保存
再将博文重新生成,部署,不出意外,即可看见效果
如果live2d被遮挡住,可以进入live2d-widget文件夹下的waifu.css
找到z-index
,将后面的数值修改为一个较大的数,数字越大,所在图层越高
我这里设置的是99999
一般情况下,这样就可以用了。
3.进阶微调
先将进入live2d-api,然后fork到自己的仓库,再将自己的仓库git clone
到自己的本地,放在主题的source文件夹下,这个路径记住
然后,修改live2d-widget文件夹下的autoload.js
将cdnPath修改为live2-api的路径,例如
cdnPath: "/live2d-api/Blog_live2d_api/",
修改模型大小比例与位置
如果需要修改模型大小比例与位置,进入live2d-api的model文件夹下,进入需要修改的模型文件夹,找到index.json
文件,找到layout
部分,进行微调
"layout": {
"center_x":0.0,
"center_y":-0.1,
"width":2.0
},
我这里以蕾姆的为例
修改live2d插件的样式
如果需要修改整个live2d的位置的话,进入live2d-widget文件夹下的waifu.css
以下是我的配置,可做参考
#waifu-toggle {
background-color: rgba(100, 179, 243, 0.048);
border-radius: 50px;
bottom: 80px;
color: #f4f9fa6e;
cursor: pointer;
font-size: 24px;
right: 0;
margin-right: 30px;
padding: 5px 2px 5px 5px;
position: fixed;
transition: margin-left 1s;
width: 150px;
writing-mode: horizontal-tb;
}
#waifu-toggle.waifu-toggle-active {
margin-left: -50px;
}
#waifu-toggle.waifu-toggle-active:hover {
margin-left: -30px;
}
#waifu {
bottom: -1000px;
right: 0;
line-height: 1;
margin-bottom: -5px;
position: fixed;
transform: translateY(3px);
transition: transform .3s ease-in-out, bottom 3s ease-in-out;
z-index: 999999;
}
#waifu:hover {
transform: translateY(0);
}
#waifu-tips {
animation: shake 50s ease-in-out 5s infinite;
background-color: rgba(60, 220, 248, 0.356);
border: 1px solid rgba(48, 176, 235, 0.62);
border-radius: 12px;
box-shadow: 0 3px 15px 2px rgba(191, 158, 118, .2);
font-size: 14px;
line-height: 24px;
margin: -30px 20px;
min-height: 70px;
opacity: 0;
overflow: hidden;
padding: 5px 10px;
position: absolute;
text-overflow: ellipsis;
transition: opacity 1s;
width: 250px;
word-break: break-all;
}
#waifu-tips.waifu-tips-active {
opacity: 1;
transition: opacity .2s;
}
#waifu-tips span {
color: #0099cc;
}
#live2d {
cursor: grab;
height: 300px;
position: relative;
width: 300px;
}
#live2d:active {
cursor: grabbing;
}
#waifu-tool {
color: #aaa;
opacity: 0;
position: absolute;
right: 5px;
top: 70px;
transition: opacity 1s;
}
#waifu:hover #waifu-tool {
opacity: 1;
}
#waifu-tool span {
display: block;
height: 30px;
text-align: center;
}
#waifu-tool svg {
fill: #7b8c9d;
cursor: pointer;
height: 25px;
transition: fill .3s;
}
#waifu-tool svg:hover {
fill: #0684bd; /* #34495e */
}
如果需要live2d小人在左边的话
#waifu {
bottom: -1000px;
right: 0;
line-height: 1;
margin-bottom: -5px;
position: fixed;
transform: translateY(3px);
transition: transform .3s ease-in-out, bottom 3s ease-in-out;
z-index: 999999;
}
将这部分的right修改为left即可
修改live2d的文本
进入live2d-widget文件夹下的waifu-tips.json
就可以按照自己的想法修改
删除模型
进入live2d-api文件夹下的model_list.json
即可看见使用的模型以及切换看板娘对应的语句
不需要的删去即可,记得去model文件夹也将对应的模型删去
当然,也可以不删,需要用的时候,可以回到model_list.json
加回去
增加模型
这一部分暂时还没摸索,之后有机会看情况补充
有关live2d-widget和live2d-api的其他信息,也可直接去找到对应的github仓库,看看issue,或许你的问题已经被解答了。
Issues · stevenjoezhang/live2d-widget (github.com)
写在最后
其实最花时间的是waifu.css
和对应model的微调,毕竟要调整到适配自己网站再加上自己满意的情况,还是需要些时间滴