猿问

jquery实时监听div高度变化

$(".btn1").click(function(){
$("#box").animate({height:"300px"}); 
});

我想实时的监听$("#box")的高度,请问该如何操作呢?


皈依舞
浏览 5942回答 1
1回答

素胚勾勒不出你

<!DOCTYPE html><html><head>&nbsp; <meta charset="UTF-8">&nbsp; <title>Document</title>&nbsp; <script src="jquery.min.js"></script>&nbsp; <style>&nbsp; &nbsp; #box{&nbsp; &nbsp; &nbsp; height: 100px;&nbsp; &nbsp; &nbsp; width: 100px;&nbsp; &nbsp; &nbsp; background: red;&nbsp; &nbsp; }&nbsp; </style></head><body>&nbsp; <div id="box"></div>&nbsp; <button class="btn1">dianwo</button>&nbsp; <script>&nbsp; &nbsp; $(".btn1").click(function(){&nbsp; &nbsp; &nbsp; $("#box").animate({height:"300px"}, {step: function(){console.log($(this).height())}}).resize(function() {&nbsp; &nbsp; &nbsp; &nbsp; console.log($(this).height());&nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; });&nbsp; </script></body></html>
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答