Frage

Ich versuche es so zu gestalten, dass beim Laden der Seite Kreise angezeigt werden, was in Ordnung ist, aber ich möchte, dass sie nach außen wachsen, also von der Mitte aus klein nach groß, nicht von oben links:

Was ich aktuell habe, könnt ihr hier sehen: http://thomasbritton.co.uk/projects/ebrd/

Idealerweise soll dies in CSS erfolgen, Sie können aber auch JS verwenden, wenn es einfacher/stabiler ist.

Irgendwelche Ideen?

Hier ist mein CSS auch für den Animationsteil:

.circle a {
  border-radius: 150px;
  color: #fff;
  height: 0;
  position: absolute;
  text-decoration: none;
  width: 0;
}

.circle a.grow {
  -webkit-animation-name: grow;
  -webkit-animation-duration: 2.2s;
  -webkit-animation-timing-function: ease;
  -webkit-animation-iteration-count: 1;
  -webkit-animation-direction: normal;
  -webkit-animation-delay: 0;
  -webkit-animation-play-state: running;
  -webkit-animation-fill-mode: forwards;

  -moz-animation-name: grow;
  -moz-animation-duration: 2.2s;
  -moz-animation-timing-function: ease;
  -moz-animation-iteration-count: 1;    
  -moz-animation-direction: normal;
  -moz-animation-delay: 0;
  -moz-animation-play-state: running;
  -moz-animation-fill-mode: forwards;

  animation-name: grow;
  animation-duration: 2.2s;
  animation-timing-function: ease;
  animation-iteration-count: 1; 
  animation-direction: normal;
  animation-delay: 0;
  animation-play-state: running;
  animation-fill-mode: forwards;
}

@-webkit-keyframes grow {
  0% { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); }
}

@-moz-keyframes grow {
  0% { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); height: 168px; width: 168px; }
}

@keyframes grow {
  0% { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); }
}
War es hilfreich?

Lösung

Hier ist ein grobes Beispiel dafür, was Sie tun müssen: jsfiddle.net/UxtJV/.Es verwendet ein wenig JS, um eine Klasse zum Animieren des Kreises hinzuzufügen.Es ist width, height, top Und left Eigenschaften werden animiert und es wird gegeben position: relative.

div.circle {
    position: relative;

    width: 0px;
    height: 0px;
    top: 50px;
    left: 50px;

    -webkit-transition-duration: 2s;
    -webkit-transition-property: all;
    -webkit-transition-timing-function: ease-in-out;

    text-align: center;
    background: red;
    color: white;
    border-radius: 100%;
    padding: 20px;
    overflow: hidden;
}

div.circle.open {
    top: 0px;
    left: 0px;
    width: 100px;
    height: 100px;
}​

Andere Tipps

Zu diesem Zweck sollte Ihre Animation Folgendes beinhalten:

  1. Breite und Größe erhöhen.
  2. Erhöhen Sie oben und links.

Es ist ein bisschen Arbeit, aber es wird genau das tun, was Sie gefragt haben.

Sie können versuchen, Ihre Animation mit der Übersetzungseigenschaft zu kombinieren.

Dies könnte eine weitere Option sein:

transform-origin: top right; /* 50% 50% or whatever*/

Wie veröffentlicht hier...

Nur für den Fall, dass jemand nach einer funktionierenden JQuery -Lösung sucht, ist es hier ...

Html

<div class=circle1></div>

CSS

.circle1 {
    position:absolute; top:50px; left:50px;
    width: 0px; height: 0px;
    border:1px solid red;
    padding:20px;
    border-radius:50%;
}

JS

$(".circle1").mouseover(function() {
      $(this).animate({top:"0", left:"0", width:"100px", height:"100px", opacity: 0}, 200);  
}).mouseout(function() {
      $(this).animate({top:"50px", left:"50px", width:"0", height:"0", opacity: 1}, 200);
});

Und hier ist die Demo - - http://jsbin.com/esiluleb/1/

Sie müssen JQuery oder JavaScript für Ihren Fall nicht verwenden, Sie können dies mit reinem CSS erreichen.

Verwenden Sie keine Positionseigenschaft auf Ihren animierten Divs. Das führt zu verzögerten Animationen. Verwenden Sie stattdessen Transformation für Performantenanimationen.

<div class="circle__wrapper">
  <a class="circle" href="#"></a>
</div>

/* circle__wrapper will help you to position the div in the center of the page */
.circle__wrapper { 
  position: fixed; 
  top: 50%; 
  left: 50%; 
  -webkit-transform: translate(-50%, -50%); 
  transform: translate(-50%, -50%); 
}

.circle__wrapper a.circle { 
  display:block; 
  height: 168px; 
  width: 168px; 
  background-color: #fea733; 
  -webkit-border-radius: 50%; 
  -moz-border-radius: 50%; 
  border-radius: 50%; 
  -webkit-animation: growUp 2s 1.5s; /* You can remove 1.5s if you don't want delay */
  -moz-animation: growUp 2s 1.5s; 
  -ms-animation: growUp 2s 1.5s; 
  -o-animation: growUp 2s 1.5s; 
  animation: growUp 2s 1.5s; 
}


@-webkit-keyframes growUp {   
  0%  { -webkit-transform: scale(0); }
  100% { -webkit-transform: scale(1); }
}

@-moz-keyframes growUp {
  0%  { -moz-transform: scale(0); }
  100% { -moz-transform: scale(1); }
}

@-o-keyframes growUp {
  0%  { -o-transform: scale(0); }
  100% { -o-transform: scale(1); }
}

@-ms-keyframes growUp {
  0%  { -ms-transform: scale(0); }
  100% { -ms-transform: scale(1); }
}

@keyframes growUp {
  0%  { transform: scale(0); }
  100% { transform: scale(1); }
}

Hoffe das hilft.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top