Solved

jQuery ui draggable: saving to canvas

Posted on 2014-10-27
2
250 Views
Last Modified: 2014-10-28
I have a product image (prodimage) and with a button click I can add it to a canvas. For now both the product image and the canvas are on the same html page.

function CanvasIt() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("prodimage");
ctx.drawImage(img, 10, 10);
};

Open in new window


I also have some draggable images and after the are positioned over the prodimage I would like to add them to the same canvas.

<script type="text/javascript">
$(function() {
	
	$("#graphicCount11").draggable({ 
		containment: "#product-image-wrapper", 
		scroll: false,
		stop: function(event, ui) {
		   };
	 });
</script>

Open in new window


Anyone have an idea of how this can be done?
0
Comment
Question by:garysamuels
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40407559
test page : http://jsfiddle.net/rt20paok/

jQuery(document).ready(function() {
    CanvasIt();
	$("#graphicCount11").draggable({ 
		containment: "#product-image-wrapper", 
		scroll: false,
		stop: function(event, ui) {
            var c = document.getElementById("myCanvas");
            var ctx = c.getContext("2d");
            var img = $(this).get(0);
            ctx.drawImage(img, 10, 10);
        }
	 });
});

function CanvasIt() {
    var c = document.getElementById("myCanvas");
    var ctx = c.getContext("2d");
    var img = document.getElementById("prodimage");
    ctx.drawImage(img, 10, 10);
};

Open in new window

0
 

Author Closing Comment

by:garysamuels
ID: 40409123
thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now