Assigned width in percentage but want to get it in pixels

前端 未结 11 1236
北荒
北荒 2020-12-15 15:07



        
11条回答
  •  忘掉有多难
    2020-12-15 15:39

    .width() gets "...the current computed width" of the element that is used on, per the jQuery width documentation: http://api.jquery.com/width/, so the return value from $('#heatMapBar').width() is in pixels, not percent. I would suggest using developers tool to check the width, it may be that in #heatMapBar's current context, its width is 100px.

    If you look here: http://jsfiddle.net/NkQXa/1/ you will see that #test is set to width:50%;, but it alerts the actual pixel width.

提交回复
热议问题