css3 - expanding/animating a div from center when width is 100% -


i have div border , used keyframes expand onload want expand center rather left right.

http://andylilien.com/index2015.html

the css:

.navback {  position:absolute; bottom:0px; padding-bottom:-8px; width:100%; height:17px; background-color:#fff; border-top: 1px solid #d0d0d0; z-index:999; }    @-webkit-keyframes expandline{ 0%{width:0%;} 50%{width:50%;} 100%{width:100%;} } .navback{ -webkit-animation:expandline 2s; } 

adjust height , width doing, transform element positioning left , top appropriately.

also, don't need keyframe animations if you're using common easing function or linear animation.

#expander {    position:absolute;    width: 0;    height: 17px;    background-color: #fff;    border-top: 1px solid red;    z-index: 999;    transform: translate(-50%, -50%);    top: 50%;    left: 50%;    -webkit-animation: expandline 2s;  }    @-webkit-keyframes expandline{    0%   { width:   0%; }    50%  { width:  50%; }    100% { width: 100%; }  }
<div id="expander"></div>

what's happening css:

  • start element off in it's initial position (fully styled , positioned, 0 width)
  • add transition element defining attributes transition, , how long transition take
    • now time 1 of specified attributes changes, apply transition rather instantly applying change
  • define class represents final state of element (fully styled , positioned, in initial state, width want)

the expanding center behavior result of:

/* #expander positioned relative nearest ancestor position other `static`, or `body` element if nothing else qualifies */ position: absolute;  /* top of #expander 50% down positioning context's height (i.e., top of #expander vertically centered in parent) */ top: 50%;  /* left of #expander 50% of positioning context's width (i.e., left of #expander horizontally centered in parent) */ left: 50%;  /* translate #expander 50% of own width left, , 50% of own height in direction */ transform: translate(-50%, -50%); 

since don't animate transform, continues apply defined in initial rule: keep #expander vertically , horizontally centered in parent, regardless of how tall or wide is.

now use whatever trigger appropriate (you said using onload) apply expanded class , trigger transition.

hope helps.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -