journey-ad / live2d_src

基于 https://github.com/EYHN/hexo-helper-live2d 的修改版
GNU General Public License v2.0
239 stars 53 forks source link

live2d.js raised Uncaught TypeError: Cannot read property 'addEventListener' of null #4

Closed zehuichen123 closed 6 years ago

zehuichen123 commented 6 years ago

I use hexo to generate my files. I don't know where to put my live2d.js so that I can access it through relative address. Thus, I put my live2d.js in folder blogFolder/node_modules/hexo-helper-live2d/assets/Pio (since I find hexo will put all files in the pointed figure's folder into blogFolder/public/live2d/assets/, which allow me to access this file by writing:

<script src="/live2d/assets/live2d.js"></script>
    <script type="text/javascript">
        loadlive2d("live2d", "./live2d/assets/Pio.model.json");
    </script>

But when I run my site in localhost:4000, only figure image is visible while text hasn't been shown. And this is error message in my console:

Uncaught TypeError: Cannot read property 'addEventListener' of null
    at o (live2d.js:582)
    at L (live2d.js:800)
    at (index):1814
o @ live2d.js:582
L @ live2d.js:800
(anonymous) @ (index):1814

Here is my live2d.js line 582:

function o(t) {
    C = document.getElementById(t), C.addEventListener && (window.addEventListener("click", g), window.addEventListener("mousedown", g), window.addEventListener("mousemove", g), window.addEventListener("mouseup", g), document.addEventListener("mouseout", g), window.addEventListener("touchstart", y), window.addEventListener("touchend", y), window.addEventListener("touchmove", y))
}

Here is my live2d.js line 800:

function L(t, i, e) {
        X = void 0 === e ? .5 : e, o(t), n(i)
    }

Here is index line 1814:

<script type="text/javascript">
        loadlive2d("live2d", "./live2d/assets/Pio.model.json");
</script>

Can someone tell me what's wrong with my live2d??? I am quite confused since I know little about js. Your suggestions/ solutions will be highly appreciated! QAQ
ps. I used theme next in hexo. You can view my site or just comment below if you want more imfomation.

zehuichen123 commented 6 years ago

I used another live2d repository to solve this problem, still with some errors raised in my site when I viewed the console in Chrome. QAQ

journey-ad commented 6 years ago

抱歉这两天事情比较多,现在才有空回复 关于你提到的问题,这是我代码的问题,当时只实现了功能,没做兼容处理 如果要用我提供的live2d.js,model.json目前必须添加如下字段值

"hit_areas_custom":{
    "head_x":[-0.35, 0.6],
    "head_y":[0.19, -0.2],
    "body_x":[-0.3, -0.25],
    "body_y":[0.3, -0.9]
}

否则就会报错,寒假期间代码不会更新,可以先看看这个项目

zehuichen123 commented 6 years ago

我知道啦~ 谢啦 而且我的mouseover好像是失效的 = =