最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show and grow animation on page load in jQuery - Stack Overflow

programmeradmin3浏览0评论

I'm trying to make a div show and then grow to its appropriate size. Here is my code so far:

$(document).ready(function() {
$('#enlarge').css("visibility", "visible").animate({
    height:681, width:467
}, 1000, "linear", function(){alert("all done");});

});

My HTML is simple:

    <div id="enlarge"><span>content here</span></div>

My CSS is even more simple:

#enlarge {
    height:0px;
    width:0px;
    background: url(../img/enlarge.png)no-repeat;
    z-index: 3;
    position:absolute;
    top:-50px;
    left:250px;
    visibility: hidden;
}

I'm trying to make a div show and then grow to its appropriate size. Here is my code so far:

$(document).ready(function() {
$('#enlarge').css("visibility", "visible").animate({
    height:681, width:467
}, 1000, "linear", function(){alert("all done");});

});

My HTML is simple:

    <div id="enlarge"><span>content here</span></div>

My CSS is even more simple:

#enlarge {
    height:0px;
    width:0px;
    background: url(../img/enlarge.png)no-repeat;
    z-index: 3;
    position:absolute;
    top:-50px;
    left:250px;
    visibility: hidden;
}
Share Improve this question asked Sep 12, 2013 at 19:24 AmidudeAmidude 3512 gold badges6 silver badges15 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 2

Here's a Fiddle

<div id="enlarge">
  <span>content here</span>
</div>


#enlarge {
  background: #555;
  height: 0;
  width: 467px;
  z-index: 3;
  position:absolute;
  top:-50px;
  left:250px;
}


$(function() {
  $('#enlarge').animate({ height: '681px' }, 1000, 'linear');
});

and if you want to animate both width & height than

#enlarge {
  background: #555;
  height: 0;
  width: 0;
  z-index: 3;
  position:absolute;
  top:-50px;
  left:250px;
}


$(function() {
  $('#enlarge').animate({ height: '681px', width: '467px' }, 1000, 'linear');
});
$('#enlarge').animate({
    height:681px,
    width:467px
}, 1000);

The .css() call is extraneous. EDIT: thanks for catching the px

You have to use opacity as there is no animation for visible, which is a boolean:

$(document).ready(function() {
    $("#enlarge").animate({"opacity": "1", "height":"700px", "width":"467px"},5000);
});
发布评论

评论列表(0)

  1. 暂无评论