[个人配置] 博客园SimpleMemory添加Live 2D不生效解决方法
看别人的博客操作添加Live 2D看板娘,把代码添加到页首、页尾、侧边栏都不生效。浏览SimpleMemory官方文档发现提供了一套钩子函数,使用后成功解决问题
不生效代码
<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
<script>
setTimeout(function () {
L2Dwidget.init({
"model": {
//jsonpath控制显示那个小萝莉模型,
//(切换模型需要改动)
// "https://unpkg.com/(live2d-widget-model-koharu)@1.0.5/assets/(koharu).model.json"
jsonPath: "https://unpkg.com/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json",
"scale": 1
},
"display": {
"position": "right", //看板娘的表现位置
"width": 150, //小萝莉的宽度
"height": 300, //小萝莉的高度
"hOffset": 0,
"vOffset": -20
},
"mobile": {
"show": true,
"scale": 0.5
},
"react": {
"opacityDefault": 0.7,
"opacityOnHover": 0.2
}
});
}, 1000);
</script>
把下方代码添加到 window.cnblogsConfig 同级的script标签里
window.cnblogsConfig.hooks = {
beforeCode: (_) => {
$.getScript('https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js',function(){
setTimeout(function () {
L2Dwidget.init({
"model": {
//jsonpath控制显示那个小萝莉模型,
//(切换模型需要改动)
// "https://unpkg.com/(live2d-widget-model-koharu)@1.0.5/assets/(koharu).model.json"
jsonPath: "https://unpkg.com/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json",
"scale": 1
},
"display": {
"position": "right", //看板娘的表现位置
"width": 150, //小萝莉的宽度
"height": 300, //小萝莉的高度
"hOffset": 30,
"vOffset": -160
},
"mobile": {
"show": true,
"scale": 0.5
},
"react": {
"opacityDefault": 0.7,
"opacityOnHover": 0.2
}
});
}, 200);
});
}
};
不在主页显示,随便打开一篇随笔可以看到狗狗出来了
2022/3/9 今天又出问题了,原因是手机预览狗狗太大了,添加一个PC、手机端判断
window.cnblogsConfig.hooks = {
beforeCode: (_) => {
var userAgentInfo = navigator.userAgent;
var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
var xx,yy,xxx,yyy;
if(flag==false){
xx = 75;
xxx = 30;
yy = 150;
yyy = -60;
}
else {
xx = 150;
xxx = 30;
yy= 300;
yyy = -60;
}
$.getScript('https://cdn.jsdelivr.net/gh/wangsrGit119/wangsr-image-bucket/L2Dwidget/js/L2Dwidget.min.js',function(){
setTimeout(function () {
L2Dwidget.init({
"model": {
//jsonpath控制显示那个小萝莉模型,
//(切换模型需要改动)
// "https://unpkg.com/(live2d-widget-model-koharu)@1.0.5/assets/(koharu).model.json"
jsonPath: "https://unpkg.com/live2d-widget-model-wanko@1.0.5/assets/wanko.model.json",
"scale": 1
},
"display": {
"position": "right", //看板娘的表现位置
"width": xx, //小萝莉的宽度
"height": yy, //小萝莉的高度
"hOffset": xxx,
"vOffset": yyy
},
"mobile": {
"show": true,
"scale": 0.5
},
"react": {
"opacityDefault": 0.7,
"opacityOnHover": 0.2
}
});
}, 200);
});
}
};