Uncaught ReferenceError: canvasLock is not defined

Uncaught ReferenceError: canvasLock is not defined

(function () {

    window.canvasLock = function (obj) {

        this.height = obj.height

        this.width = obj.width

    }


    canvasLock.prototype.initDom = function () {

        var wrap = document.createElement('div')

        var str = '<h4 id="title" class="title">绘制解锁图案</h4>'

        wrap.setAttribute('style', 'position:absolute;top:0;right:0;bottom:0;left:0')


        var canvas = document.createElement('canvas')

        canvas.setAttribute('id', 'canvas')

        canvas.style.cssText = 'background-color:#305066;display:inlink-block;margin-top:15px'


        wrap.innerHTML = str

        wrap.appendChild(canvas)


        var width = this.width || 300

        var height = this.height || 300


        document.body.appendChild(wrap)


        // 高清屏缩放

        canvas.style.width = width + 'px'

        canvas.style.height = height + 'px'

    }


    // 程序初始化

    canvasLock.prototype.init = function () {

        this.initDom()

    }

})()

----------------------

<!DOCTYPE html>

<html lang="en">


<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>手势解锁</title>

    <style>

        body {

            background: #305066;

            text-align: center;

        }

        h4 {

            color: #22C3AA;

        }

    </style>

</head>


<body>

    

    <script src="./src/index.js"></script>

    <script>

        // 1 生成背景

        // 2 动态title生成

        // 3 用js动态生成canvas标签

        // 4 js方式动态生成h3标签和canvas标签

        new canvasLock({}).init()

    </script>

</body>


</html>


正在回答

登陆购买课程后可参与讨论,去登陆

1回答

同学你好,使用同学提供的代码测试,控制台没有报错,如下:

http://img1.sycdn.imooc.com//climg/5f72e5bc09af9a2312980591.jpg

可能是js文件引入的问题,按照同学的引入路径,index和src文件夹应该在同一目录下,js文件应该在src文件夹下,如下图

http://img1.sycdn.imooc.com//climg/5f72e61e092e7c2802370143.jpg

同学可以排查下目录结构是不是有问题,如果排查不出来,可以把自己的目录截图上来,老师帮助排查,祝学习愉快~

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
3.WebAPP开发与小程序
  • 参与学习           人
  • 提交作业       622    份
  • 解答问题       6815    个

微信带火了小程序,也让前端工程师有了更多的展现机会,本阶段带你从移动基础知识的学习到webAPP开发,及小程序开发,让你PC端与移动端两端通吃。

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师