Reputation: 15
Hello to this great community,
I have the following lines of Code for an expanding span:
CSS
.spacer {
width:100%;
position: relative;
background-color: red;
}
.spacer > span {
display: inline-block;
height: 20px;
background-color: yellow;
}
SCRIPT
$(function() {
$(".spacer > span").each(function() {
$(this)
.data("origWidth", $(this).width())
.width(0)
.animate({
width: $(this).data("origWidth")
}, 2500);
});
});
HTML
<div class="spacer"><span style="width: 90%"></span></div>
The span expands automatic to the width which is set, e.g. 90% of the spacer. If I change the Browserwindow width after that, the spacer follows fine but the span keeps its width. How is possible expand the span to 90% and then make it fluid to the spacer width?
Upvotes: 0
Views: 632
Reputation: 123397
$(function() {
$(".spacer > span").each(function() {
var w = this.style.width;
// get the width property defined as inline style
$(this)
.data("origWidth", w)
.width(0)
.animate({
width: $(this).data("origWidth")
}, 2500);
});
});
Upvotes: 2