나는 여전히 붙어있어서 내 캔버스 프로젝트에 도움이 필요하다. 나는 템플릿에 대한 아이디어를 얻었고, 거기서보고 싶은 내용이 있으며, 여기에 내용을 삽입하고 싶습니다. 마지막 질문에서 저는이 작업 캔버스 템플릿을 가지고 있습니다 : jsfiddle.net/AbdiasSoftware/LmCwZ/2/ 여기 내 첫 번째 탭에서 갖고 싶은 아이디어가 있습니다. 첫 번째 기본 탭을 만드는 데 도움이 되었기를 바랍니다. 예제를 확장하고 직접 작업 할 것입니다.
첫 번째 탭 예 : http://i.imgur.com/5Anzfny.png
첫 번째 탭에서 어떻게 할 수 있습니까? 일부 텍스트 내용은 응용 프로그램별로 자동으로 업데이트되어야합니다. 미리 감사드립니다.HTML5 캔버스로 가져 오는 방대한 콘텐츠
0
A
답변
0
@Ken은 지난 질문에 대한 답변에서 복잡한 내용의 레이아웃은 대개 HTML + CSS를 사용하여 수행됩니다. 탭을 제공하는 좋은 도구는 jqueryUI의 탭 컨트롤입니다. https://jqueryui.com/tabs/ 프로덕션 응용 프로그램은 HTML + CSS를 사용합니다.
하지만 학습을 목적으로 프로젝트를 코딩 했으므로 다음은 탭 콘텐츠 용으로 "템플릿"을 만드는 방법입니다.
JavaScript에는 object
이라는 변수가 있습니다. 하나의 객체가 여러 개의 정보를 저장할 수 있기 때문에 객체는 배열과 비슷합니다. 객체의 각 정보에는 레이블이 지정됩니다.
당신은 다음과 같을 수 템플릿에 포함 할 텍스트에 대한 정보를 보유하는 객체 :
var myTextObject1 = { text:"Hello", x:100, y:20 };
var myTextObject2 = { text:"World", x:100, y:35 };
이 템플릿을 만들려면 컨텐츠 배열을 생성하고 해당 배열에 객체를 저장
var contents=[];
contents.push(myTextObject1);
contents.push(myTextObject2);
이 탭을 활성화 할 때
그런 다음 당신은 당신의 탭의 내용을 그립니다 개체를 사용할 수 있습니다
for(var i=0;i<contents.length;i++){
drawTextContent(contents[i]);
}
function drawTextContent(text){
ctx.fillText(text.text,text.x,text.y);
}
,536,
물론 다른 종류의 객체를 생성해야합니다 :
- 텍스트를 정의하는 객체.
- 이미지를 정의하는 객체입니다.
- 배경 사각형을 정의하는 객체입니다.
- 자막 이미지 (이미지 + 텍스트)를 정의하는 객체입니다. http://jsfiddle.net/m1erickson/WNaLn/
: 여기<!doctype html> <html> <head> <link rel="stylesheet" type="text/css" media="all" href="css/reset.css" /> <!-- reset css --> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <style> body{ background-color: ivory; } canvas{border:1px solid red;} </style> <script> $(function(){ // get a reference to the canvas and context var canvas=document.getElementById("canvas"); var ctx=canvas.getContext("2d"); // the contents[] array will hold individual content objects // the content objects will be used to later draw the content to the tab var contents=[]; // load a test image var house=new Image(); house.onload=start; house.src="houseIcon.png"; function start(){ // create some test contents // tab background addBackgroundRect(0,0,275,275,"red"); // left panel example addBackgroundRect(10,10,100,250,"lavender"); addImageContent(house,50,15,20,20); addImageContent(house,75,65,20,20); addImageContent(house,50,110,20,20); addImageContent(house,15,65,20,20); addImageContent(house,40,65,30,30); // right panel example addBackgroundRect(110,10,150,100,"white"); addTextContent("Text1",115,20,"red"); addTextContent("Text2",115,40,"red"); addTextContent("Text3",115,60,"red"); addTextContent("Text4",115,80,"red"); addTextImageContent("Caption",house,175,20,60,60); drawContents(contents); } // draw all content in the contents array function drawContents(contents){ for(var i=0;i<contents.length;i++){ var content=contents[i]; // switch (content.type){ case "background": drawBackgroundRect(content); break; case "text": drawTextContent(content); break; case "image": drawImageContent(content); break; case "textImage": drawTextImageContent(content); break; default: break; } } } // draw contents based on a content object function drawBackgroundRect(bk){ ctx.fillStyle=bk.color; ctx.fillRect(bk.x,bk.y,bk.width,bk.height); } // function drawTextContent(text){ ctx.fillStyle=text.color; ctx.fillText(text.text,text.x,text.y); } // function drawImageContent(img){ ctx.drawImage(img.image,img.x,img.y,img.width,img.height); } // function drawTextImageContent(tImg){ ctx.drawImage(tImg.image,tImg.x,tImg.y,tImg.width,tImg.height); ctx.fillStyle="black"; ctx.fillRect(tImg.x,tImg.y+tImg.height-15,tImg.width,15); ctx.fillStyle="white"; ctx.fillText(tImg.text,tImg.x+5,tImg.y+tImg.height-4); } // create content objects function addBackgroundRect(x,y,width,height,color){ contents.push({ type:"background", x:x, y:y, width:width, height:height, color:color }); } // function addTextContent(text,x,y,color){ contents.push({ type:"text", text:text, x:x, y:y, color:color }); } // function addImageContent(imgObject,x,y,width,height){ contents.push({ type:"image", image:imgObject, x:x, y:y, width:width, height:height }); } // function addTextImageContent(text,imgObject,x,y,width,height){ contents.push({ type:"textImage", text:text, image:imgObject, x:x, y:y, width:width, height:height }); } }); // end $(function(){}); </script> </head> <body> <canvas id="canvas" width=300 height=300></canvas> </body> </html>
은 예제 코드와 데모를 시작하고있다
관련 문제
- 1. 콘텐츠를 iframe contenteditable에서 HTML5 캔버스로 가져 오기
- 2. html5 캔버스로 텍스트 조작
- 3. HTML5 캔버스로 플로팅
- 4. HTML5 캔버스로 이미지 회전
- 5. 상호 작용을 통해 드로어 블에서 이미지를 캔버스로 가져 오는 방법
- 6. 두 이미지를 HTML5 캔버스로 그립니다.
- 7. HTML5 캔버스로 이미지를 타일로 자르다
- 8. HTML5 캔버스로 ... 비율을 어떻게 유지합니까?
- 9. HTML5 캔버스로 아이콘 색상 마스킹
- 10. 두 이미지를 html5 캔버스로 업로드
- 11. 동영상에서 캔버스로 HTML5 이미지 그리기
- 12. HTML5 캔버스로 드래그 앤 드롭
- 13. 큰 이미지에서 html5 캔버스로 뷰포트
- 14. 저장 캔버스로 그리기 html5 phonegap
- 15. HTML5 캔버스로 애니메이션 GIF 생성
- 16. 필터를 HTML5 캔버스로 구현 한 SVG
- 17. 드래그 모양 HTML5 캔버스로 만든 후
- 18. PHP 쿼리에서 html5 캔버스로 base64 이미지 전달
- 19. HTML5 캔버스로 이미지/텍스처의 원근감 변환
- 20. HTML5 캔버스로 간단한 자동차 게임 만들기
- 21. png로 html5 캔버스로 렌더링 된 mathml 저장
- 22. 이진 데이터에서 html5 캔버스로 이미지 표시
- 23. 벡터를 HTML5 캔버스로 변환 (DXF에서 캔버스 좌표로)
- 24. div의 일부분을 HTML5 및 캔버스로 투명하게 만듭니다.
- 25. HTML5 캔버스로 실제로 그리는 법 배우기
- 26. 큰 배열의 이미지를 html5 캔버스로 그립니다.
- 27. ASP.NET 및 HTML5 캔버스로 브라우저 게임 만들기
- 28. HTML5 툴바에서 이미지를 캔버스로 드래그 앤 드롭
- 29. 콘텐츠 쿼리로 아이콘을 가져 오는 방법은 무엇입니까?
- 30. HTML5 캔버스에서 좌표를 가져 오는 방법은 무엇입니까?