Hello,
I'm using jQuery and trying to create a plugin that draws a rectangle on a canvass. However, it will not even work.. I have tried to create it when I click on a button, this does not work either.. Here is the code:
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
.cancasing {
margin-left: 200px;
margin-top: 100px;
border-style:solid;
border-width:1px;
width:900px;
height:500px;
}
</style>
</head>
<script type="application/javascript">
jQuery.fn.drawRect = function(options) {
var defaults = {
text: 'Default text for div element',
x: 10,
y: 10,
w: 100,
h: 200
};
var options = jQuery.extend(defaults, options);
return this.each(function() {
$(this) = $(document.createElement('div')).css({border: '1px dotted black'}).addClass("ui-boxer-helper");
});
};
$(function()
{
var canvas = $("#canvas")[0];
var ctx = canvas.getContext("2d");
$('#start').click(function()
{
alert ('Hello world');
$.drawRect(
{
text: 'Hello world'
});
});
});
</script>
</head>
<body>
<canvas id="canvas" class="cancasing"></canvas>
<button id="start">Start</button>
</body>
</html>
Any suggestions please?