Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
增加模型左右设置(#10)(#19)(#21)(#23) 增加移动端模型更多功能(#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiazeyu committed Oct 28, 2017
1 parent 4a79abe commit b3041f3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions dist/device.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 31 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,55 @@ function registerDir(pathname, dir) {
hexo.extend.generator.register('live2d', function (locals) {
return generators;
});

registerDir('live2d/assets/', path.resolve(__dirname, './assets'));
registerFile('live2d/script.js', path.resolve(__dirname, './dist/bundle.js'))

hexo.extend.helper.register('live2d', function (config) {
var config = Object.assign(
{
model:"z16",
model: "z16",
width: 150,
height: 300,
mobileShow: "true",
mobileWidth: 75,
mobileHeight: 150,
position: "right",
horizontalOffset: 0,
bottomOffset: -20,
className: "live2d",
id: "live2dcanvas",
bottom: -20
},
config,
hexo.config.live2d
);
return `
<script type="text/javascript" src="/live2d/script.js"></script>
<canvas id="${config.id}" width="${config.width}" height="${config.height}" class="${config.className}"></canvas>
<style>
#${config.id} {
position: fixed;
right: 0px;
${config.position}: ${config.horizontalOffset}px;
z-index: 999;
pointer-events: none;
bottom: ${config.bottom}px;
bottom: ${config.bottomOffset}px;
}
</style>
<script>loadlive2d(${JSON.stringify(config.id)} ,${JSON.stringify(url.resolve("/live2d/assets/",models[config.model]))},0.5)</script>
<script src="live2d/device.min.js"></script>
<script type="text/javascript">
(function(){
if(device.mobile()){
if(${config.mobileShow}){
document.getElementById("${config.id}").width = ${config.mobileWidth};
document.getElementById("${config.id}").height = ${config.mobileHeight};
document.write('<script type="text/javascript" src="/live2d/script.js"><\\/script>');
document.write('<script>loadlive2d(${JSON.stringify(config.id)}, ${JSON.stringify(url.resolve("/live2d/assets/", models[config.model]))}, 0.5)<\\/script>');
}
}else{
document.write('<script type="text/javascript" src="/live2d/script.js"><\\/script>');
document.write('<script>loadlive2d(${JSON.stringify(config.id)}, ${JSON.stringify(url.resolve("/live2d/assets/", models[config.model]))}, 0.5)<\\/script>');
}
})();
</script>
`
});
});

registerDir('live2d/assets/', path.resolve(__dirname, './assets'));
registerFile('live2d/script.js', path.resolve(__dirname, './dist/bundle.js'));
registerFile('live2d/device.min.js', path.resolve(__dirname, './dist/device.min.js'));

0 comments on commit b3041f3

Please sign in to comment.