簡體   English   中英

如何將Raphael JS紙張的寬度和高度設置為其包含div的寬度和高度?

[英]How to set the width and height of a Raphael JS paper same as those of its containing div?

我的Raphael JS論文是在id為“ temp”的div中創建的。 我希望紙張的高度和寬度與div temp的高度和寬度相同。 如何使用javascript或jquery執行此操作?

的HTML

<div id="temp" style="border:1px solid red;width:500px;height:500px"></div>

我嘗試使用獲取高度和寬度

document.getElementById("temp").style.width 
document.getElementById("temp").style.height 

但是當我用它來創建紙張時,我收到了JS警告。

如果您的JavaScript中包含以下RaphaelJS初始化:

var paper = new Raphael('myDiv');

在html中:

<div id="myDiv" style="width: 200px; height: 200px;" />

在這里,拉斐爾紙將是200px x 200px。 它會自動執行。

您可以使用.. height()width() jQuery函數來獲取元素的高度和寬度。

var width=$("#temp").width(); 
var hieght=$("#temp").height(); 
alert(width); //gives you width
alert(height); //gives you height

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM