Animations and Transitions

30 Jun 202322 minutes to read

Animations

Fade animation

In Carousel, two built-in animations are provided for slide transitions. You can disable animation using the AnimationEffect property. By default, Slide animation is applied for the transition between slides.

The following demo depicts the example for Fade animation,

@using Syncfusion.EJ2.Navigations;

    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").AnimationEffect(CarouselAnimationEffect.Fade)
            .Items(new List<CarouselItem> {
                    new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>"  }
                })
                .Render()
            )
    </div>


<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Carousel fade animation

Custom animation

In Carousel, you can use customized animation effects for slide transitions using the Custom option of the AnimationEffect property and apply custom animation css via cssClassproperty.

The following demo depicts the example for parallax custom animation,

@using Syncfusion.EJ2.Navigations;

<div class="control-container">
    @(Html.EJS().Carousel("defaultCarousel").
         AnimationEffect(CarouselAnimationEffect.Custom).CssClass("parallax")
        .Items(new List<CarouselItem>
        {
        new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>" },
        new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
        new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
        new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>" },
        new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>" }
        })
    .Render()
    )
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }

    /* Parallax animation */
    .parallax .e-carousel-item {
        transition: transform 1s ease-in-out;
    }

        .parallax .e-carousel-item.e-next {
            animation: ParallaxIn 1s ease-in-out;
        }

        .parallax .e-carousel-item.e-prev {
            animation: ParallaxOut 1s ease-in-out;
        }

    @@keyframes ParallaxIn {
        from {
            opacity: 0;
            transform: scale(0) translateY(100%);
        }

        to {
            opacity: 1;
            transform: scale(1) translateY(0);
        }
    }

    @@keyframes ParallaxOut {
        from {
            opacity: 1;
            transform: scale(1) translateY(0);
        }

        to {
            opacity: 0;
            transform: scale(0) translateY(-100%);
        }
    }
</style>
public ActionResult Index()
{
    return View();
}

Carousel custom animation

Intervals between slides

Using the items property, you can set different intervals for each item to transition between slides. The default interval is 5000 ms (5 seconds). The following example depicts the code for setting the different intervals between each item.

@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").Items(new List<CarouselItem> {
                    new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>", Interval = 3000  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>", Interval = 2000 },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>", Interval = 1000 },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>", Interval = 5000  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>", Interval = 6000  }
                })
                .Render()
            )
    </div>
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Note: Interval property can accept value in terms of milliseconds.

Auto play slides

In the carousel, all slides transitions are performed continuously after the specified or default intervals. You can enable or disable the auto slide transition using the AutoPlay property. The following example depicts the code to disable the auto slide transitions.

@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").AutoPlay(false).Items(new List<CarouselItem> {
            new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>" }
            })
            .Render()
            )
    </div>
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Pause on hover

By default, Slide transitions are paused when hovering the mouse pointer over the Carousel element. You can enable or disable this functionality using thePauseOnHover property.

The following example depicts the code to play the slides when hovering the mouse pointer over the Carousel element.

@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").PauseOnHover(false).Items(new List<CarouselItem> {
                    new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>"  }
                })
                .Render()
            )
    </div>
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Looping slides

In the carousel, slides transitions are repeated continuously when you reach the last slide by default. You can enable or disable the infinite slide transition using the Loop property. The following example depicts the code to disable the infinite slide transitions.

@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").Loop(false).Items(new List<CarouselItem> {
                    new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>"  }
                })
                .Render()
            )
    </div>
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Carousel loop slides

Slide changing events

Using the SlideChanging or SlideChanged events of the Carousel component, you can perform sample end customization while the carousel items are switched.

The following demo depicts the example for carousel events,

@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel")
            .SlideChanging("onSlideChanging")
            .SlideChanged("onSlideChanged")
            .Items(new List<CarouselItem> {
                    new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>"  }
                })
                .Render()
            )
    </div>
</div>
<script type="text/javascript">
    function onSlideChanging(args) {
        console.log(args.currentSlide); // You can customize the slide before changing
    }
    function onSlideChanged(args) {
        console.log(args.currentSlide); // You can customize the slide after changed
    }
</script>
<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers
{
    public partial class AccordionController : Controller
    {
        // GET: //
        public IActionResult DefaultFunctionalities()
        {
            return View();
        }
        public ActionResult PartialView1()
        {
        
            return PartialView();

        }

        public ActionResult PartialView2()
        {

            return PartialView();

        }

    }
}

Disable touch swiping

In the carousel, you can swipe the carousel slides using touch actions by default. The swipe action can be enabled or disabled using the EnableTouchSwipe property. The following example depicts the code to disable the swipe action for the slide.

@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").EnableTouchSwipe(false).Items(new List<CarouselItem> {
                    new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>"  },
                    new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>"  }
                })
                .Render()
            )
    </div>
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Swipe Modes

In the carousel, the swipeMode property allows specifying whether the slide transition should occur while performing swiping via touch or mouse. The slide swiping is enabled or disabled using the bitwise operator.

The following are the different swipe modes available in the carousel:

  • CarouselSwipeMode.Touch - Allows the user to slide the slides using touch actions.
  • CarouselSwipeMode.Mouse - Allows the user to slide the slides using mouse actions.
  • CarouselSwipeMode.Touch & CarouselSwipeMode.Mouse - Allows the user to slide the slides using both touch and mouse actions.
  • ~CarouselSwipeMode.Touch & ~CarouselSwipeMode.Mouse - Disables both touch and mouse actions.
@using Syncfusion.EJ2.Navigations;

<div class="container">
    <div class="control-container">
        @(Html.EJS().Carousel("defaultCarousel").AutoPlay(false).SwipeMode(CarouselSwipeMode.Mouse & CarouselSwipeMode.Touch).Items(new List<CarouselItem> {
            new CarouselItem { Template = "<div class='slide-content'>Slide 1</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 2</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 3</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 4</div>" },
            new CarouselItem { Template = "<div class='slide-content'>Slide 5</div>" }
            })
            .Render()
            )
    </div>
</div>

<style>
    .control-container {
        background-color: #adb5bd;
        height: 300px;
        margin: 0 auto;
        width: 500px;
    }

    .e-carousel .slide-content {
        align-items: center;
        display: flex;
        font-size: 1.25rem;
        height: 100%;
        justify-content: center;
    }
</style>
public ActionResult Index()
{
    return View();
}

Carousel Swipe Mode