我正在做一个在线购物网站项目。为此,我需要在画布上添加多个图像,例如腰带、帽子、衬衫或裤子。最后画布应该作为图像导入。
有人建议我如何做,还帮助我向画布添加多个可拖动和可调整大小的图像。请帮帮我
这就是我试图做的。
<html lang="en">
<head>
<title>Outfit Demo</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/>
<script type="text/javascript">
jQuery(document).ready(function(event){
$("#shirt").resizable().draggable();
$('.pic1').live('mouseover',function(){
$(this).resizable().draggable();
});
});
var shirt;
var pant;
function selectshirt(src)
{
shirt = src;
path = "<img class=\"pic1\" src=\""+src+"\" height=\"300px\" width=\"300px\"/>";
invisible("shirtcontainer");
visible("pantcontainer");
document.getElementById("shirt").innerHTML=document.getElementById("shirt").value+path;
document.getElementById("cart").style.visibility="visible";
}
function selectpants(src)
{
pant = src;
path = "<img class=\"pic1\" src=\""+src+"\" height=\"400px\" width=\"300px\"/>";
document.getElementById("trousers").innerHTML=path;
}
function addtocart()
{
alert("Shirt:"+shirt+"\npant:"+pant);
}
function changeshirt()
{
visible("shirtcontainer");
invisible("pantcontainer");
}
function changepant()
{
visible("shirtcontainer");
invisible("pantcontainer");
}
function visible(containername)
{
document.getElementById(containername).style.visibility="visible";
}
function invisible(containername)
{
document.getElementById(containername).style.visibility="hidden";
}
</script>
</head>
<body>
<div id="leftpanel" style="position:absolute;left:0;width:33%;">
<div style="left:0;height:30%;" id="shirt"></div>
<div style="left:0;height:70%;" id="trousers"></div>
<div style="left:0;height:70%;" id="cart">
<button onclick="changeshirt()">Change Shirt</button>
<button onclick="addtocart()">Add to cart</button>
</div>
</div>
<div id="middlepanel" style="width: 100%; height: 100%; position:absolute;left:500;width:33%;overflow:auto;">
<div id="shirtcontainer">
<img src="images/shirts/shirt1.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt2.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt3.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt4.png" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt5.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt6.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
<img src="images/shirts/shirt7.jpg" height="300px" width="300px" onclick="selectshirt(this.src)"/>
</div>
</div>
<div id="rightpanel" style="width: 100%; height: 100%; position:absolute;right:0;width:33%;overflow:auto;">
<div id="pantcontainer">
<img src="images/pants/pant1.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant2.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant3.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant4.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant5.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant6.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
<img src="images/pants/pant7.jpg" height="300px" width="300px" onclick="selectpants(this.src)"/>
</div>
</div>
</body>
<script>
invisible("pantcontainer");
invisible("cart");
</script>
</html>