【问题标题】:issues with jquery and canvas elementjQuery和Canvas元素的问题
【发布时间】:2012-01-20 20:22:59
【问题描述】:

这是我的代码:

$('#add_shape').click(function() {
                            var rectHeight = $('#rect_height_input').val();
                            var WidthOrRadius = $('#widthorradius').val();

                            $('<canvas>').attr({
                                id:'canvas'                             
                            }).css({
                                height:function() {
                                    if (rectHeight > 0) {
                                        return rectHeight + 'px';
                                    }
                                    else {
                                        return WidthOrRadius + 'px';
                                    }
                                },
                                width:WidthOrRadius + 'px'
                            })
                            .appendTo('#work_area');
                                var canvas = document.getElementById('canvas');
                                var ctx = canvas.getContext('2d');                              

                                ctx.fillStyle = $('#color_list option:selected').val();
                                ctx.fillRect(0, 0 , WidthOrRadius, rectHeight);

});

此代码适用于 jsfiddle(此处为:http://jsfiddle.net/dzejkej/xwg5f/),但不适用于我的浏览器。我不知道出了什么问题。有人可以帮忙吗?

【问题讨论】:

  • @czarchaic--firefox 最新版本

标签: javascript jquery html5-canvas


【解决方案1】:

如果您使用 HTML5 编写代码,这将给出正确的结果。

你确定你是用 HTML5 编码的吗?

【讨论】:

  • @Robin_Michael_Poothurai——我很确定我是。在 html5 中编码不需要额外的插件吗?只是一个文档类型?
  • @codeninja,是的。你是对的 HTML5 不需要任何额外的插件,但所有浏览器都不会支持 HTML5 仅最新版本,因为有些标签也不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多