[英]Add easing to jquery function
如何使此jQuery函數平滑過渡(平滑調整高度)?
我不確定在哪里添加它。
jQuery('#my-button').click(function() {
if (jQuery('#my-button').height() < 100) {
jQuery('#my-button').css("height","auto");
}
else {
jQuery('#my-button').css("height","56px");
}
});
我嘗試使用animate(),但在'auto'上不起作用。
我不能使用固定高度,因為它需要對其他設備進行文本響應。
您可以使用CSS轉換,然后只使用相同的代碼即可。
CSS過渡
過渡:延遲持續時間屬性計時功能;
transition-timing-function屬性指定過渡效果的速度曲線,並可以具有以下值:
jQuery('#my-button').click(function(){ if (jQuery('#my-button').height() < 100) { jQuery('#my-button').css("height","auto"); } else{ jQuery('#my-button').css("height","56px"); } });
#my-button{ -webkit-transition: all 500ms linear; -moz-transition: all 500ms linear; -o-transition: all 500ms linear; -ms-transition: all 500ms linear; transition: all 500ms linear; border: 1px solid #ccc; width: 200px; height:200px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="my-button">Hello Button</div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.