荣耀彩票代理

IT技术互动交流平台

如何对Canvas里的width与height进行设置

作者:whl  发布日期:2018-11-13 08:57:00

  CanvasSHIHTML5LIZUIXINZENGJIADEYIGEYUANSU,DIANNAOYONGHUHUIZHITUXINGDESHIHOUYONGQIJINXINGCAOZUOHUIFAXIANGUOCHENGBIANDESHIFENJIANDANKUAIJIE。XIAMIANZHUYAOJIDAJIADUICanvasZHONGSHEZHIwidthHEheightJIANGHUICHUXIANDEWENTIJINXINGXIANGXIJIEDA,SHILIDAIMAYEYOUJIDAJIAYIYILIECHU,YOUXUYAODEPENGYOUGANJINYIQILAIXUEXIBA!

  ZUIJINYINWEIGONGZUOXUYAO,SUOYIJIUXUELEYIXIAHtmlZHONGDECanvasBIAOQIAN。

  CanvasSHIHTML5XINZENGDEZUJIAN,TAJIUXIANGYIKUAIMUBU,KEYIYONGJavaScriptZAISHANGMIANHUIZHIGEZHONGTUBIAO、DONGHUADENG。

  没有Canvas的年代,绘图只能借助Flash插件实现,页面不得不用JavaScript和Flash进行交互。有了Canvas,我们就再也不需要Flash了,直接使用JavaScript完成绘制。

荣耀彩票代理  DANGWOKANLEYIXIAJIAOCHENGHOU,ZIJIXIELEYIGEhello worldDESHIHOU,MAFANSHIJIUCHUXIANLE。KANXIAMIANDAIMA:

hello world代码

  SHANGMIANDAIMADEYISI,SHIYAOZAIYIGEwidthHEheightGEWEI200pxDEcanvasSHANGHUAYITIAOZHIXIAN,GAIZHIXIANDEQIDIANWEI(0,0),ZHONGDIANWEI(200,200);

  然而浏览器画出来的图像却是:

画出来的图像

荣耀彩票代理  YIKANZHEITU~ZENMESHIZHEIYANGDEXIEDU?BUYINGGAIA~BENYINGGAISHIYIGEDUIJIAOXIANCAIDUIA~~

  HOULAICHALEYIXIAZILIAOCAIZHIDAO,canvasBIAOQIANSHEZHIwidthHEheightDESHIHOU,YOUYIXIAJIZHONGFANGSHIHECHANSHENGDEHOUGUO:

产生的后果

  SUOYI,TONGGUOSHANGMIANDEZILIAOBIANKEZHIDAOQIYUANYINJIUSHIWOSHANGMIANLIZIZHONGDAIMAHUIRANGcanvasDEKUANGAOBEILASHENLE,CONGERSHIDETUXIANGGENYUXIANGDEBUYIZHIDE。

  XIANZAIWOZHONGXIELEYIFENZHENGQUESHEZHIcanvasKUANGAODAXIAODEDAIMALIZI:

canvas宽高代码例子

  JIEGUO:

结果

  ZONGJIE

  KANDAOZHEILIXIANGXINDAJIADOUFAXIANCanvasDEHAOCHULEBA,XIANGQIYIQIANYONGFlashCHAJIANDAOZHIDEYIDUIMAFANSHISHIZAISHIYIBAXINSUANLEI,KEYISHUOCanvasDECHUXIANYIDINGCHENGDUSHANGJIEFANGLEDAJIADESHUANGSHOU,BUZAIZAIHUAFEIDALIANGDESHIJIANLAICAOZUOLE。RUGUODAJIADUISHANGMIANDEJIANGJIEHAIYOUYIWENDEHUAKEYILIUYAN,XIAOBIANHUIHEDAJIAYIQITAOLUNJIEJUEDE。

延伸阅读:

Tag标签:   
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规