2015-10-14 164 views
1

當我使用jQuery調整大小調整div的寬度時,沒有得到正確的寬度。 將寬度從250px調整爲200px在jQuery中獲取寬度爲250px。但背景顏色位置是200px。我再次調整大小從200px到150px獲得值是200px。爲什麼我有起始寬度的位置。請幫助我得到結束寬度的位置。使用jQuery調整大小後調整大小後的寬度

請檢查我的代碼和附加的圖像下面,糾正我?

https://jsfiddle.net/duL8gu3b/17/

CSS

#profile #graph #bar1 #bar1_slider { 
    background: #1640c0; 
    width: 250px; 
} 

JS

$("#graph .slider").resizable({ 
     animateEasing: "easeOutBounce", 
     helper: "ui-resizable-helper", 
     animate: true, 
     handles: 'w', 
     maxWidth: 250, 
     grid: [ 50, 10 ] , 
     stop: function(event, ui) { 
      /*graph = ui["size"]["width"]/50; 
      alert(graph);*/ 
      var graph1 = $("#bar1_slider").width()/50; 

      $.post("/graph", { graph1: graph1}, 
        function (response) { 
      }); 
     } 
    }); 

enter image description here

+0

已嘗試過'ui.size.width'嗎? –

+0

@SandeepNayak,是的,我試過這個。但結果相同 –

+0

請提供jsfiddle。 – Alex

回答

0

問題是動畫。 jquery在動畫完成之前返回寬度值,所以元素的寬度沒有改變。您可以在1秒延遲後返回值。 Check this

animateDuration: 0 
+0

太棒了!!!!。我知道了。謝謝 –

+0

@samsam歡迎您 – Alex

相關問題