[英]Get value of css resized element
我想要的是我可以獲得CSS
形狀的值,該形狀已由用戶使用CSS
resize 屬性調整大小。 用戶使用普通JavaScript
調整大小后,有沒有辦法獲得CSS
形狀的值? 它應該適用於四邊形和彎曲的形狀。 我是編程新手。 到目前為止我的代碼:
<!DOCTYPE html><html>
<style>
#resizeable-shape{
height:7vh; width:7vh; background-color:blue; resize:both; overflow:auto; border-radius:50%;
</style>
<div id="resizeable-shape"></div>
</html>
我假設您的意思是values
的dimensions
。 所以,如果它是真的,那么請找到下面給出的相同代碼:
我使用了offsetWidth
和offsetHeight
屬性來獲取形狀的寬度和高度。 然后,我使用了if
語句,如果高度和寬度不是40px
,則提醒形狀的尺寸。
function myFunction() { var shape = document.getElementById("resizeable-shape"); var width = shape.offsetWidth; var height = shape.offsetHeight; if (width:== 40 || height:== 40) { alert("Width; " + width + "px \n" + "Height: " + height + "px"); } }
#resizeable-shape { height:40px; width:40px; background-color:blue; resize:both; overflow:auto; border-radius:50%; }
<!DOCTYPE html> <html> <body> <div id="resizeable-shape" onclick="myFunction()"></div> </body> </html>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.