
Originally Posted by
Beverleyh
Basing height on content is the same as height:auto;...
Yes, I suppose it would be.
Ok, I'm trying something different this time.
I'm adding an "inner" div to each of the original divs. The inner div gets the text content and resizes itself based on the content. It has no background color or border so it's invisible as far as the viewer is concerned (not to be confused with its visibility being set to "invisible" or its display being set to "none"). The outer (original) divs now have fixed heights and widths. The outer divs still have the transition class and the inner divs don't have any classes.
So now when you click on one of the buttons, something like this happens:
var LeftBigButton_Click = function()
{
$("#LeftDiv").show(0); // <-- show the outer div (in case it was invisible before)
$("#LeftInnerDiv").html(sixLines); // <-- add text to the inner div. Should be added immediately. No transition. Overflow on outer div is hidden.
$("#LeftDiv").css("height", $("#LeftInnerDiv").height() + "px"); // <-- change the height of the outer div to match that of the inner div. Expecting transition.
};
So after the text is added to the inner div, which should change its height/width immediately (no transition), I set the height/width of the outer div to match that of the inner div. <-- I'm expecting a transition to occur at this point. But nothing.
Should changing the height trigger a transition if it's done via object.css("height", value)? Similar question for width.
Here's a link: http://www.mm-theory.com/shahspace/t...ransition.html
Here's the code:
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Transition</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link href="CSS\jquery-ui.css" rel="stylesheet" />
<link href="CSS\jquery-ui.structure.css" rel="stylesheet" />
<link href="CSS\jquery-ui.theme.css" rel="stylesheet" />
<script src="Script\jquery-1.11.1.min.js"></script>
<script src="Script\jquery-ui.min.js"></script>
<style>
.transitionWidthClass{
-webkit-transition: width 1s ease-in;
-moz-transition: width 1s ease-in;
-o-transition: width 1s ease-in;
transition: width 1s ease-in;
}
.transitionHeightClass{
-webkit-transition: height 1s ease-in;
-moz-transition: height 1s ease-in;
-o-transition: height 1s ease-in;
transition: height 1s ease-in;
}
</style>
</head>
<body style="text-align: center;">
<table style="width: 100%; height: 100vh;" border="1">
<tr>
<td style="width: 50%;">
<div id="LeftDiv" class="transitionWidthClass" style="display: inline-block; background-color: green; border: 3px blue solid; border-radius: 4px; height: 54px; overflow: hidden;">
<div id="LeftInnerDiv" style="display: inline-block;">
line 1<br/>
line 2<br/>
line 3
</div>
</div>
<br/>
<br/>
<br/>
<input type="button" value="Hide" onclick="LeftHideButton_Click();"/>
<br/>
<input type="button" value="Small" onclick="LeftSmallButton_Click();"/>
<br/>
<input type="button" value="Big" onclick="LeftBigButton_Click();"/>
</td>
<td style="width: 50%;">
<div id="RightDiv" class="transitionHeightClass" style="display: inline-block; background-color: red; border: 3px blue solid; border-radius: 4px; width: 88px; height: 18px; white-space: nowrap; overflow: hidden;">
<div id="RightInnerDiv" style="display: inline-block;">
one two three
</div>
</div>
<br/>
<br/>
<br/>
<input type="button" value="Hide" onclick="RightHideButton_Click();"/>
<br/>
<input type="button" value="Small" onclick="RightSmallButton_Click();"/>
<br/>
<input type="button" value="Big" onclick="RightBigButton_Click();"/>
</td>
</tr>
</table>
<script>
var threeLines = "line 1<br/>line 2<br/>line 3";
var sixLines = "line 1<br/>line 2<br/>line 3<br/>line 4<br/>line 5<br/>line 6";
var threeWords = "one two three";
var sixWords = "one two three four five six";
$(document).ready(function() {
$(window).on("webkitTransitionEnd", function(event)
{
if ($("#LeftDiv").html() === "")
{
$("#LeftDiv").hide();
}
if ($("#RightDiv").html() === "")
{
$("#RightDiv").hide();
}
});
});
var LeftHideButton_Click = function()
{
$("#LeftInnerDiv").html("");
$("#LeftDiv").css("height", $("#LeftInnerDiv").height() + "px");
};
var LeftSmallButton_Click = function()
{
$("#LeftDiv").show(0);
$("#LeftInnerDiv").html(threeLines);
$("#LeftDiv").css("height", $("#LeftInnerDiv").height() + "px");
};
var LeftBigButton_Click = function()
{
$("#LeftDiv").show(0);
$("#LeftInnerDiv").html(sixLines);
$("#LeftDiv").css("height", $("#LeftInnerDiv").height() + "px");
};
var RightHideButton_Click = function()
{
$("#RightInnerDiv").html("");
$("#RightDiv").css("width", $("#RightInnerDiv").width() + "px");
};
var RightSmallButton_Click = function()
{
$("#RightDiv").show(0);
$("#RightInnerDiv").html(threeWords);
$("#RightDiv").css("width", $("#RightInnerDiv").width() + "px");
};
var RightBigButton_Click = function()
{
$("#RightDiv").show(0);
$("#RightInnerDiv").html(sixWords);
$("#RightDiv").css("width", $("#RightInnerDiv").width() + "px");
};
</script>
</body>
</html>
Bookmarks