我有一個PNG,這是一個市場計劃。這個想法是讓計劃中的每個點都可點擊。我計劃使用area
標籤來實現此目標。我還想向用戶展示不可用的斑點是紅色的還是用十字或其他東西標記的。所以我想在圖片上畫一些東西來表明這一點。現在我想知道實現這個目標的最好方法是什麼。有人對此有個好主意嗎?什麼是最好的方式來繪製HTML中的圖像的東西?
0
A
回答
1
想必你將擁有所有空間的座標在你的市場。
下面是如何使用這些座標加畫布標記爲紅色的未使用空間:
- 尺寸屏幕外的畫布佈局規劃圖像的大小
- 畫在畫布上
- 使用的佈局規劃用半透明紅色(或其他顏色)填充畫布的不可用座標
- 將屏幕img元素的.src設置爲畫布:img.src = canvas.toDataURL();
代碼和演示:http://jsfiddle.net/m1erickson/Wj9Sx/
<!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 reference to show(the checkbox) and img(the img)
$show=$("#show");
$show.hide();
$show.change(function(){draw($show[0].checked);});
$img=$("#plan");
// create an offscreen canvas
// used to put
var canvas=document.createElement("canvas");
var ctx=canvas.getContext("2d");
// set coordinates for unavailable spaces
var nonAvailable=[]
nonAvailable.push([
{x:100,y:27},
{x:177,y:27},
{x:138,y:91},
]);
nonAvailable.push([
{x:215,y:46},
{x:260,y:92},
{x:213,y:137},
{x:168,y:92},
]);
// load the floorplan img
var img=new Image();
img.crossOrigin="anonymous";
img.onload=start;
img.src="https://dl.dropboxusercontent.com/u/139992952/stackoverflow/geo.png";
// resize the canvas to the img size
// display the img
function start(){
canvas.width=img.width;
canvas.height=img.height;
$show.show();
var imgElement=document.getElementById("plan");
imgElement.src=img.src;
}
// display the floorplan
// optionally fill the unavailable spaces with transparent fill
function draw(showUnavailable){
// draw the floorplan
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.drawImage(img,0,0);
// return if we're not showing unavailables
if(showUnavailable){
// set fill to 15% red
ctx.save();
ctx.fillStyle="red";
ctx.globalAlpha=.15;
// fill any non-available places
// with semi-transparent red
for(var i=0;i<nonAvailable.length;i++){
var pts=nonAvailable[i];
ctx.beginPath();
ctx.moveTo(pts[0].x,pts[0].y);
for(var j=1;j<pts.length;j++){
ctx.lineTo(pts[j].x,pts[j].y);
}
ctx.closePath();
ctx.fill();
}
// restore the context state
ctx.restore();
}
// draw the modified image back to the img element
var imgElement=document.getElementById("plan");
imgElement.src=canvas.toDataURL();
}
}); // end $(function(){});
</script>
</head>
<body>
<input type="checkbox" id="show">Indicate non-available spaces.<br>
<img id="plan" />
</body>
</html>
2
你可以使用一種叫做a map的東西,並將其絕對定位在你的圖像上。
或者,你可以使用一種叫做canvas tag in html5這就需要JavaScript的,雖然這是很難用它更加有用和穩定
1
恕我直言,你應該通過創建與其他圖像的斑點,將它們放置做到這一點那個png。這樣,您就可以添加懸停效果等,以這些點..
,如:
CSS:
#png1 {
position: absolute;
z-index:1;
}
#spot1 {
display: block;
overflow: hidden;
position: absolute;
z-index:2;
left: 10px;
top: 15px;
}
HTML:
<div class="wrapper" style="position: relative">
<img src="some.png" id="png1" />
<a href="spot1" id="spot1"><img src="spot-red.png" /></a>
</div>
相關問題
- 1. 使用Flex 3繪製像這樣的東西的最佳方式是什麼?
- 2. 什麼是最好的方式來標準化分數排名的東西?
- 3. 什麼是在Gtk +中繪製圖像的最快方式?
- 4. 什麼是最好的/正確的方式來覆蓋圖像
- 5. 什麼是最好的方式來定位一個'框架'在html中的東西?
- 6. 什麼是最好的方式來設置圖像imageview
- 7. 什麼是最好的方式來追加HTML只是一次?
- 8. 什麼是最好的Python開源庫來繪製圖表?
- 9. 在Windows.Forms中繪製圖像的最快方法是什麼?
- 10. 什麼是在另一幅圖像上繪製圖像的最快方式?
- 11. 什麼是使用pygame繪製圖像的好方法?
- 12. 什麼是Google Web Toolkit最好的.Net相對應的東西?
- 13. 什麼是最好的方式來實現Cocoa/Objective-C中的項目可視列表(如東西)
- 14. 什麼是最好的地方來存儲圖像
- 15. django最初的東西是什麼?
- 16. 什麼是最好的方式來控制這些計時器?
- 17. 什麼是最好的方式來獲取資產目錄的矢量圖像
- 18. 什麼是最好的方式來設置與Django的圖像遠期過期?
- 19. 更快的方式來繪製圖像
- 20. 什麼是改變圖像視圖來源的最佳方式?
- 21. 繪製統計圖表的最佳方式是什麼?
- 22. 在Google地圖上繪製點的最佳方式是什麼?
- 23. 什麼是最好的方式來查看$ .validator中的消息?
- 24. 什麼是最好的方式來清理URL中的標題
- 25. 什麼是最好的方式來返回webapi中的數據
- 26. 什麼是最好的方式來刪除像「?」的網址中的參數?
- 27. 什麼是最好的方式發送HTML /圖像電子郵件?
- 28. 從URL到可繪製或位圖的圖像:最好和最快的方式
- 29. 什麼是最好的方法上傳隊列中的圖像
- 30. MKOverlayView繪製混合模式的東西
哇,謝謝你的擴展帖子,真的很感激! – Martijn