[英]How to Toggle (or Scale) to reduce a DIV's vertical size (but only to 30% of initial height)
所以我有一個跨越頁面寬度的 DIV(地圖),但我希望有一個按鈕,用戶可以單擊“隱藏/取消隱藏”DIV,單擊時基本上會做三件事:
這是我到目前為止所得到的:目前它只縮小到正確的垂直高度
真的很感謝幫助...
<!-- JQUERY STUFF ADDED IN THE HEAD-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<!-- THE CODE -->
<div id="map">
Map Content Is Here
</div>
<p class="hidemap">HIDE MAP</p>
<script>
$(document).ready(function() {
$("p.hidemap").click(function () {
$("#map").effect("scale", { percent: 25, direction: 'vertical' }, 500);
});
});
</script>
嘗試這樣的事情:
var orig_height = $('#map').height();
$('.hidemap').click(function()
{
if($('#map').height() == orig_height)
{
var new_height = Math.floor(orig_height * .25) + 'px';
var new_opacity = '.3';
}
else
{
var new_height = orig_height + 'px';
var new_opacity = '1';
}
$('#map').animate(
{
height: new_height,
opacity: new_opacity
},1000);
});
基於 Alien 的,在這里你有:
<div id="map" style="overflow:hidden"> <!-- Look at the style -->
Map Content Is Here <br>
This is the seccond line
</div>
<p class="hidemap">HIDE MAP</p>
劇本:
var orig_height = $('#map').height();
$('p.hidemap').click(function()
{
var new_height = orig_height;
var new_opacity = 1;
if($('#map').height() == orig_height){
new_height = Math.floor(orig_height * .01);
new_opacity = .3;
}
$('#map').animate({
height: new_height,
opacity: new_opacity
}, 2000);
});
希望這可以幫助。 干杯
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.