C
Bölüm 7: CSS Animasyonları ve Transitions
Genel Bakış

Bölüm 7: CSS Animasyonları ve Transitions

15 Haziran 2025
10 dk okuma süresi
css-animasyonlar-transitions

CSS Animations’a Giriş

CSS animasyonları, web sitelerinizi canlı ve etkileşimli hale getiren güçlü araçlardır. İki ana yöntemle animasyon oluşturabilirsiniz: Transitions (basit geçişler) ve Keyframe Animations (karmaşık animasyonlar).

CSS Transitions

Transitions, CSS özelliklerindeki değişiklikleri yumuşak geçişlerle gerçekleştirir.

Temel Transition Syntax

.element {
    transition: property duration timing-function delay;
}
 
/* Örnek */
.button {
    background-color: blue;
    transition: background-color 0.3s ease-in-out;
}
 
.button:hover {
    background-color: red;
}

Transition Özellikleri

.element {
    /* Hangi özellik animasyonlanacak */
    transition-property: background-color;
    transition-property: all;                    /* Tüm özellikler */
    transition-property: transform, opacity;     /* Birden fazla */
    
    /* Animasyon süresi */
    transition-duration: 0.3s;
    transition-duration: 300ms;
    
    /* Zamanlama fonksiyonu */
    transition-timing-function: ease;            /* Varsayılan */
    transition-timing-function: linear;
    transition-timing-function: ease-in;
    transition-timing-function: ease-out;
    transition-timing-function: ease-in-out;
    transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
    
    /* Gecikme */
    transition-delay: 0.1s;
}

Timing Functions

/* Hazır timing functions */
.linear { transition-timing-function: linear; }
.ease { transition-timing-function: ease; }
.ease-in { transition-timing-function: ease-in; }
.ease-out { transition-timing-function: ease-out; }
.ease-in-out { transition-timing-function: ease-in-out; }
 
/* Özel cubic-bezier */
.custom {
    transition-timing-function: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    /* Bounce effect */
}
 
/* Steps function */
.steps {
    transition-timing-function: steps(5, end);
    /* 5 adımda discrete geçiş */
}

Pratik Transition Örnekleri

1. Button Hover Effects

.btn {
    background: #007acc;
    color: white;
    padding: 12px 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}
 
/* Renk değişimi */
.btn-color:hover {
    background: #0056b3;
}
 
/* Gölge efekti */
.btn-shadow {
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: box-shadow 0.3s ease;
}
 
.btn-shadow:hover {
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}
 
/* Transform efektleri */
.btn-scale:hover {
    transform: scale(1.05);
}
 
.btn-lift:hover {
    transform: translateY(-2px);
}
 
.btn-rotate:hover {
    transform: rotate(5deg);
}
 
/* Kombine efektler */
.btn-combo {
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
 
.btn-combo:hover {
    background: #0056b3;
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

2. Card Hover Animations

.card {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}
 
.card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
 
/* Sliding overlay */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s ease;
}
 
.card:hover::before {
    left: 100%;
}
 
/* Image zoom */
.card-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    transition: transform 0.3s ease;
}
 
.card:hover .card-image {
    transform: scale(1.1);
}

3. Navigation Animations

.nav-link {
    position: relative;
    color: #333;
    text-decoration: none;
    padding: 10px 0;
    transition: color 0.3s ease;
}
 
.nav-link:hover {
    color: #007acc;
}
 
/* Underline animation */
.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: #007acc;
    transition: width 0.3s ease;
}
 
.nav-link:hover::after {
    width: 100%;
}
 
/* Slide in from center */
.nav-link-center::after {
    left: 50%;
    transform: translateX(-50%);
    transition: width 0.3s ease;
}
 
/* Background expand */
.nav-link-bg {
    position: relative;
    overflow: hidden;
    transition: color 0.3s ease;
}
 
.nav-link-bg::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: #007acc;
    transition: left 0.3s ease;
    z-index: -1;
}
 
.nav-link-bg:hover::before {
    left: 0;
}
 
.nav-link-bg:hover {
    color: white;
}

CSS Keyframe Animations

Keyframes ile karmaşık, çok aşamalı animasyonlar oluşturabilirsiniz.

Temel Keyframe Syntax

@keyframes animationName {
    0% {
        /* Başlangıç durumu */
        opacity: 0;
        transform: translateY(20px);
    }
    
    50% {
        /* Orta durum */
        opacity: 0.5;
    }
    
    100% {
        /* Bitiş durumu */
        opacity: 1;
        transform: translateY(0);
    }
}
 
.element {
    animation: animationName 1s ease-in-out;
}

Animation Özellikleri

.element {
    /* Animasyon adı */
    animation-name: slideIn;
    
    /* Süre */
    animation-duration: 1s;
    
    /* Zamanlama */
    animation-timing-function: ease-in-out;
    
    /* Gecikme */
    animation-delay: 0.5s;
    
    /* Tekrar sayısı */
    animation-iteration-count: 1;        /* Bir kez */
    animation-iteration-count: infinite; /* Sonsuz */
    animation-iteration-count: 3;        /* 3 kez */
    
    /* Yön */
    animation-direction: normal;         /* Normal */
    animation-direction: reverse;        /* Ters */
    animation-direction: alternate;      /* İleri-geri */
    animation-direction: alternate-reverse;
    
    /* Fill mode */
    animation-fill-mode: none;           /* Varsayılan */
    animation-fill-mode: forwards;       /* Son hali kalsın */
    animation-fill-mode: backwards;      /* İlk hali beklesin */
    animation-fill-mode: both;           /* Her ikisi */
    
    /* Play state */
    animation-play-state: running;       /* Çalışıyor */
    animation-play-state: paused;        /* Duraklatılmış */
}
 
/* Kısayol syntax */
.element {
    animation: slideIn 1s ease-in-out 0.5s infinite alternate forwards;
    /*         name duration timing delay iteration direction fill-mode */
}

Popüler Animation Patterns

1. Fade Animations

/* Fade In */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
 
/* Fade In Up */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
 
/* Fade In Scale */
@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
 
.fade-in { animation: fadeIn 0.6s ease-out; }
.fade-in-up { animation: fadeInUp 0.6s ease-out; }
.fade-in-scale { animation: fadeInScale 0.6s ease-out; }

2. Slide Animations

/* Slide In Left */
@keyframes slideInLeft {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}
 
/* Slide In Right */
@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}
 
/* Slide In Down */
@keyframes slideInDown {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}
 
.slide-in-left { animation: slideInLeft 0.5s ease-out; }
.slide-in-right { animation: slideInRight 0.5s ease-out; }
.slide-in-down { animation: slideInDown 0.5s ease-out; }

3. Bounce Animations

@keyframes bounce {
    0%, 20%, 53%, 80%, 100% {
        transform: translateY(0);
    }
    40%, 43% {
        transform: translateY(-20px);
    }
    70% {
        transform: translateY(-10px);
    }
    90% {
        transform: translateY(-4px);
    }
}
 
@keyframes bounceIn {
    0% {
        opacity: 0;
        transform: scale(0.3);
    }
    50% {
        opacity: 1;
        transform: scale(1.05);
    }
    70% {
        transform: scale(0.9);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}
 
.bounce { animation: bounce 1s infinite; }
.bounce-in { animation: bounceIn 0.8s ease-out; }

4. Rotate Animations

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
 
@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}
 
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}
 
.spin { animation: spin 1s linear infinite; }
.pulse { animation: pulse 1.5s ease-in-out infinite; }
.shake { animation: shake 0.5s ease-in-out; }

5. Loading Animations

/* Loading Spinner */
@keyframes spinner {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
 
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007acc;
    border-radius: 50%;
    animation: spinner 1s linear infinite;
}
 
/* Dots Loading */
@keyframes dotBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}
 
.dots-loading {
    display: flex;
    gap: 5px;
}
 
.dot {
    width: 8px;
    height: 8px;
    background: #007acc;
    border-radius: 50%;
    animation: dotBounce 1.4s ease-in-out infinite;
}
 
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
.dot:nth-child(3) { animation-delay: 0s; }
 
/* Progress Bar */
@keyframes progressBar {
    0% { width: 0%; }
    100% { width: 100%; }
}
 
.progress-container {
    width: 100%;
    height: 4px;
    background: #f0f0f0;
    border-radius: 2px;
    overflow: hidden;
}
 
.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #007acc, #00c6ff);
    border-radius: 2px;
    animation: progressBar 3s ease-in-out;
}

Interactive Animations

Hover-Triggered Animations

.card {
    transition: transform 0.3s ease;
}
 
.card:hover {
    animation: cardHover 0.6s ease-out;
}
 
@keyframes cardHover {
    0% { transform: scale(1); }
    50% { transform: scale(1.05) rotate(1deg); }
    100% { transform: scale(1.02); }
}
 
/* Pause on hover */
.rotating-element {
    animation: spin 2s linear infinite;
}
 
.rotating-element:hover {
    animation-play-state: paused;
}

Sequential Animations

/* Staggered animation */
.list-item {
    opacity: 0;
    animation: fadeInUp 0.6s ease-out forwards;
}
 
.list-item:nth-child(1) { animation-delay: 0.1s; }
.list-item:nth-child(2) { animation-delay: 0.2s; }
.list-item:nth-child(3) { animation-delay: 0.3s; }
.list-item:nth-child(4) { animation-delay: 0.4s; }
.list-item:nth-child(5) { animation-delay: 0.5s; }
 
/* CSS'de döngü ile */
@for $i from 1 through 10 {
    .list-item:nth-child(#{$i}) {
        animation-delay: #{$i * 0.1}s;
    }
}

Complex Animation Examples

1. Morphing Shapes

@keyframes morphing {
    0% {
        border-radius: 50%;
        transform: rotate(0deg);
    }
    25% {
        border-radius: 0%;
        transform: rotate(90deg);
    }
    50% {
        border-radius: 50% 0%;
        transform: rotate(180deg);
    }
    75% {
        border-radius: 0% 50%;
        transform: rotate(270deg);
    }
    100% {
        border-radius: 50%;
        transform: rotate(360deg);
    }
}
 
.morphing-shape {
    width: 100px;
    height: 100px;
    background: linear-gradient(45deg, #007acc, #00c6ff);
    animation: morphing 4s ease-in-out infinite;
}

2. Floating Animation

@keyframes floating {
    0% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-10px);
    }
    100% {
        transform: translateY(0px);
    }
}
 
.floating-element {
    animation: floating 3s ease-in-out infinite;
}
 
/* Multiple floating elements with different timing */
.float-1 { animation-duration: 2s; animation-delay: 0s; }
.float-2 { animation-duration: 3s; animation-delay: 0.5s; }
.float-3 { animation-duration: 2.5s; animation-delay: 1s; }

3. Text Animations

/* Typewriter Effect */
@keyframes typewriter {
    from { width: 0; }
    to { width: 100%; }
}
 
@keyframes blinkCursor {
    from, to { border-color: transparent; }
    50% { border-color: #007acc; }
}
 
.typewriter {
    display: inline-block;
    overflow: hidden;
    white-space: nowrap;
    border-right: 2px solid #007acc;
    animation: 
        typewriter 4s steps(40, end),
        blinkCursor 0.75s step-end infinite;
}
 
/* Character Animation */
@keyframes charFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
 
.animated-text .char {
    display: inline-block;
    opacity: 0;
    animation: charFadeIn 0.5s ease-out forwards;
}
 
.animated-text .char:nth-child(1) { animation-delay: 0.1s; }
.animated-text .char:nth-child(2) { animation-delay: 0.2s; }
.animated-text .char:nth-child(3) { animation-delay: 0.3s; }

Performance Optimizasyonu

GPU Accelerated Properties

/* ✅ GPU ile hızlandırılan özellikler */
.optimized {
    transform: translateX(100px);        /* GPU */
    opacity: 0.5;                       /* GPU */
    filter: blur(5px);                  /* GPU */
}
 
/* ❌ CPU ile işlenen özellikler */
.slow {
    left: 100px;                        /* Layout */
    width: 200px;                       /* Layout */
    height: 200px;                      /* Layout */
    background-color: red;              /* Paint */
}

will-change Property

.element {
    will-change: transform, opacity;
}
 
.element:hover {
    transform: scale(1.1);
    opacity: 0.8;
}
 
/* Animasyon bittikten sonra temizle */
.element.animation-done {
    will-change: auto;
}

Reduced Motion Support

/* Hareket azaltma tercihini destekle */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
 
/* Alternatif yaklaşım */
@media (prefers-reduced-motion: no-preference) {
    .animation {
        animation: slideIn 1s ease-out;
    }
}

Animation Libraries ve Utilities

CSS Animation Utility Classes

/* Duration utilities */
.duration-75 { animation-duration: 75ms; }
.duration-100 { animation-duration: 100ms; }
.duration-150 { animation-duration: 150ms; }
.duration-200 { animation-duration: 200ms; }
.duration-300 { animation-duration: 300ms; }
.duration-500 { animation-duration: 500ms; }
.duration-700 { animation-duration: 700ms; }
.duration-1000 { animation-duration: 1000ms; }
 
/* Delay utilities */
.delay-75 { animation-delay: 75ms; }
.delay-100 { animation-delay: 100ms; }
.delay-150 { animation-delay: 150ms; }
.delay-200 { animation-delay: 200ms; }
.delay-300 { animation-delay: 300ms; }
.delay-500 { animation-delay: 500ms; }
 
/* Ease utilities */
.ease-linear { animation-timing-function: linear; }
.ease-in { animation-timing-function: cubic-bezier(0.4, 0, 1, 1); }
.ease-out { animation-timing-function: cubic-bezier(0, 0, 0.2, 1); }
.ease-in-out { animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1); }
Ipucu

Performance İpucu: Animasyonlarda sadece transform ve opacity özelliklerini kullanmaya çalışın. Bu özellikler GPU tarafından işlenir ve daha performanslıdır.

Debugging Animations

Animation Inspector

/* Geliştirme sırasında animasyonları yavaşlat */
*, *::before, *::after {
    animation-duration: 10s !important;
    transition-duration: 2s !important;
}
 
/* Animasyon boundaries'lerini göster */
.debug-animation {
    outline: 2px solid red;
    background: rgba(255, 0, 0, 0.1);
}

Pratik Egzersizler

  1. Button hover effects koleksiyonu oluşturun
  2. Loading spinner tasarlayın
  3. Page transition animasyonları yapın
  4. Scroll-triggered animations oluşturun
  5. Interactive card animasyonları tasarlayın

En İyi Uygulamalar

  1. 60 FPS hedefleyin: Smooth animasyonlar için
  2. GPU özelliklerini tercih edin
  3. will-change kullanın ama temizleyin
  4. Reduced motion destekleyin
  5. Semantic animations oluşturun

Sıradaki Bölüm

Bir sonraki bölümde CSS Variables ve Modern Özellikler öğreneceksiniz. CSS’in en yeni ve güçlü özelliklerini keşfedeceksiniz.

Öğrendikleriniz:

  • ✅ CSS Transitions kullanımını
  • ✅ Keyframe animations oluşturmayı
  • ✅ Popüler animation patterns
  • ✅ Performance optimizasyonunu
  • ✅ Accessibility considerations

CSS animasyonları web sitenize hayat katar! Bu bilgilerle etkileyici ve kullanıcı dostu animasyonlar oluşturabilirsiniz! ✨🎬