相信有很多時(shí)候,大家都會(huì)遇到要利用 canvas畫布 生成圖片的時(shí)候.
當(dāng)然我也遇到了, 在項(xiàng)目中wxml頁(yè)面中生成的canvas之后,我發(fā)現(xiàn)怎么樣給canvas標(biāo)簽加css都無法讓canvas不影響到頁(yè)面,
<canvas style="opacity:0;position:fixed;z-index:-9999;">
// 無論是opacity 還是 z-index 都無法解決,多多少少會(huì)影響
</canvas>
幾番琢磨,想出以下解決方案: 在
canvas
外層加父標(biāo)簽,再控制父標(biāo)簽的顯示
<view style="width:0px;height:0px; overflow:hidden"> //讓父標(biāo)簽 0寬 0高 隱藏溢出
<canvas >
</canvas>
</view>
如果上述不行請(qǐng)看下面這個(gè):
<canvas style="position:fixed:left:9999px" >
// 直接讓canvas 飛到天際, 簡(jiǎn)單粗暴; 使用時(shí)注意 position的問題; 如果 fixed不行, 換其他定位試試
</canvas>
ok .. 加油寫代碼吧...