我試圖做功能.animate的jQuery對圖像的底部而不是頂部
document.getElementById('testImage').style.height='75px';
$("#testImage").animate({
height:'0px',
width:'100px'
});
它有我的形象完美的效果相反,但我希望動畫收縮可見向底部的形象,而不是頂部。這可能嗎?
我試圖做功能.animate的jQuery對圖像的底部而不是頂部
document.getElementById('testImage').style.height='75px';
$("#testImage").animate({
height:'0px',
width:'100px'
});
它有我的形象完美的效果相反,但我希望動畫收縮可見向底部的形象,而不是頂部。這可能嗎?
你只需要找到一些方法將圖像修復到問題區域的底部。例如,可以通過將容器設置爲position: relative
,將動畫元素設置爲position: absolute
和bottom: 0
來實現。
使用CSS,設置這些規則爲你的形象:
position:relative;
bottom:0px;
確保它的容器具有適當的高度。
我在一家提琴這個工作對你:
$("#testImage").animate({
height:'0px',
width:'100px',
top:'300px'
});
的CSS:
#testImage {
position:relative;
top:0;
}
我建立了下面的功能,使圖像向下動畫,與縮短高度時相反。將高度設置爲0,將「頂部」設置爲「+ =」和圖像的高度。 $(「#testImage」)。animate({height:'0px', 「top」:「+ = 75px」 }); –
您可以使用'底部的絕對位置:0px'。 – Pieter
感謝您快速回復!我最終找到了另一種解決方案,但如果我有任何問題,我會嘗試所有這些。 –