Animate.css bxSlider text animations

As I am in the process of setting up a slider for my website, I have encountered some issues.

I am utilizing bxslider and wished to incorporate animations for the text on each slide by integrating animate.css. Animate.css is quite simple: just add "animated" along with the animation name as classes to the animated element.

In essence, I want the text to appear on a slide with an animation once the slider has completed transitioning to the slide. Additionally, I prefer the text to fade out before transitioning to the next slide with the subsequent text.

Considering the slider has callback functions, I assumed it would be straightforward to append the requisite CSS classes through.

JQUERY

$(document).ready(function(){

    $(".bxslider").bxSlider({
        auto: true,
        startSlide: 0,
        slideWidth: 640,
        onSlideAfter: function(){
        $(".title").addClass("animated bounceInRight");
        $(".text").addClass("animated bounceInRight");
        },
        onSlideBefore: function(){
        $(".title").removeClass("animated bounceInRight");
        $(".text").removeClass("animated bounceInRight");
        }
  });
});

HTML

<ul class="bxslider">
  <li><img src="" />
<h1 class="title animated bounceInRight">TITLE 1</h1><p class="text animated bounceInRight">
  text text text text text text
  text text text text text text

 </p></li>
  <li><img src="" /><h1 class="title">TITLE 2</h1><p class="text">
  text text text text text text
  text text text text text text

 </p></li>
  <li><img src="" /><h1 class="title">TITLE 3</h1><p class="text">
  text text text text text text
  text text text text text text

 </p></li>
  <li><img src="" /><h1 class="title">TITLE 4</h1><p class="text">
  text text text text text text
  text text text text text text

 </p></li>
</ul>

CSS 1 (what was added to the slider's default CSS)

.bxslider {
    padding: 0;
    margin: 0;
    list-style: none;
}
.title {
    position: absolute;
    top:100px;
    left: 100px;
    color: #FFF;
    font-family: Helvetica;
}
.text {
    display: block;
    position: absolute;
    top:200px;
    left: 200px;
    color: #000;
    font-family: Helvetica;
    width: 300px;
    background: #FFF;
    -webkit-animation-delay: 1s; /* to delay text "entrance" */

}

CSS 2 (animation "trigger"... the different animations are just CSS3 animations with keyframes and so on)

.animated {
  -webkit-animation-duration: 1s;
  animation-duration: 1s;
  -webkit-animation-fill-mode: both;
  animation-fill-mode: both;
}

An example slider can be viewed online here: bxslider test.

Thus far, there exist several problems. Although I will always mention "text," this encompasses both the <h1> and the <p> tags.

First: The first slide animates properly, with the text appearing through animations. However, on the second slide, the text is already visible before the animation commences. My intention is for the text to emerge "through" the animation.

Second: Despite attempting to introduce the fadeOut effect (once more through the addition and removal of corresponding CSS classes), it does not work as expected. The fadeOut occurs after transitioning to the next slide. It seems like I might be making a fundamental mistake in adding and removing the classes, but I am unable to pinpoint it.

Third: Is it feasible to utilize different entrance effects on each slide, possibly even randomly?

Fourth: A bug appears to manifest in Safari. On my personal computer (Safari & Chrome), the slideshow initiates with the first slide. However, on the web server in Safari, the last slide is initially visible, then quickly scrolls through to the second slide...quite odd. In Chrome, the slideshow behaves normally. Following inspection of Safari's log, no issues seem to arise from the code.

Any assistance pertaining to at least the initial two problems would be greatly appreciated!

Thank you!

Answer №1

Steps to achieve this effect:

HTML structure:

<section class="slider">  
    <ul class="bxslider" >
        <li><img src="photo-1.jpg"/>
            <div class="one slider-text">your content here</div>
        </li>
        <li><img src="photo-2.jpg"/>
        <div class="slider-text">your content 2</div>
        </li>       
        <li><img src="photo-3.jpg"/>
        <div class="slider-text">your content 3</div>
        </li>                    
    </ul>
</section>

CSS styles:

.slider .slider-text {
    font-size: 250%;
    color: #fff;
    position: absolute;
    z-index: 9999;
    text-align: center;
    bottom: 20%;
    width: 100%;  
}
.slider-text {
    visibility:hidden;
}
.slider-text.active-slide {
    visibility: visible;
}

JQUERY scripting:

$('.bxslider').bxSlider({
    auto: true,
    preloadImages: 'all',
    mode: 'horizontal',
    captions: false,
    controls: false,
    pause: 5000,
    speed: 800,
    onSliderLoad: function () {
        $('.bxslider>li .slider-text').eq(1).addClass('active-slide');
        $(".slider-text.active-slide").addClass("wow animated bounceInRight");
    },
    onSlideAfter: function (currentSlideNumber, totalSlideQty, currentSlideHtmlObject) {
        console.log(currentSlideHtmlObject);
        $('.active-slide').removeClass('active-slide');
        $('.bxslider>li .slider-text').eq(currentSlideHtmlObject + 1).addClass('active-slide');
        $(".slider-text.active-slide").addClass("wow animated bounceInRight");

    },
    onSlideBefore: function () {
        $(".slider-text.active-slide").removeClass("wow animated bounceInRight");
        $(".one.slider-text.active-slide").removeAttr('style');

    }
});

Dependencies utilized:
BxSlider v4.1.2
jQuery v1.11.2
Latest Animate.css

Additional resources:
You may also incorporate wow.js for more dynamic effects.

Answer №2

One easy way to add animations to your website is by using wow js and adding classes as usual, then reinitializing wow each time.

$(document).ready(function(){
    new WOW().init();
    $('.bxslider').bxSlider({
        auto: true,
        adaptiveHeight: true,
        onSlideAfter: function () {
            new WOW().init();
        },
        onSlideBefore: function () {
            new WOW().init();
        }
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubles with CSS drop down alignment in Internet Explorer 7

I've been racking my brain all morning trying to solve this issue. My current project involves creating a website for a client, and I'm having trouble getting the dropdown menu to position correctly in IE7. It's working fine in all other br ...

How to Emphasize Html Select Element on Mobile Devices?

Is there a way to make the HTML select element on Android appear more distinguishable as a dropdown list, rather than just looking like plain text? Any suggestions for highlighting it so users can easily identify and select an option from this element? Up ...

The click event is triggering before it is able to be removed by the code preceding the trigger

Here's a scenario I recently experienced that involves some code written using JQuery. It's more of a statement than a question, but I'm curious if others have encountered this as well: <input type="submit" value="Delete" o ...

The form submission feature is malfunctioning due to JavaScript issues

I have forms that allow file uploads (images), and I am trying to restrict the size of those images to 500KB. However, for some reason, the forms are not submitting and I am unsure why. Below is the jQuery code: $('form').on('submit', ...

Each time the .click function is used in MVC jQuery, it increments the quantity but does not simultaneously replace the href

On my product detail page, I have implemented quantity up and quantity down buttons to adjust the number of items that will be added when the user clicks on the Add To Cart button. However, I am facing an issue. Every time I click the "quantity up" button ...

Crack open a JSON object

I am struggling to parse a JSON object. It seems like the code is not working, can you help me? var mock_data = { "available": [{ "UserID": 7, "UserName": "Manoj", "Language": "Java", "Score": 9, "TimeLimit": 4.0 }, { "UserID ...

Maximizing efficiency with JavaScript object reduction

let students = [ { name: "john", marks: 50, }, { name: "mary", marks: 55, }, { name: "peter", marks: 75, }, ]; I need to find the total sum of marks using the reduce method. Here is my att ...

What is the best way to create a toggle button that can show more or show less of a text snippet with animation?

Is it possible for someone to assist me with showing a long text partially and providing a "show more" button to reveal the rest, along with a "show less" option, all with some CSS animation? I was thinking of using a font awesome arrow down icon for expan ...

Adjust the text input width appropriately for the cloze exercise

My JavaScript-generated fill-in-the-blank text is causing me trouble when it comes to adjusting the size of the input boxes. Unlike others, I know exactly what the user will or should be entering. If there is a blank space like this _______________, I wa ...

Is there a way to modify the background color with Bootstrap?

While following a Bootstrap tutorial, I stumbled upon an issue that I can't seem to resolve. In my layout, I have an article and a sidebar in a row, with the article taking up 9 columns and the sidebar taking up 3 columns. The background color of the ...

The background image is not displaying correctly in the tag td

I'm struggling to display a background image inside a table data cell using CSS. <td class='details-control'></td> When I use the following CSS rules, the image is not displayed: td.details-control { background: url(http:// ...

Differences in React projects utilizing materialize-css compared to those using react-toolbox or material-ui

Is there a difference in technical benefits or code reliability when directly using material-css in JSX versus utilizing JSX specific libraries like material-ui or react-toolbox? Conversely, could using JSX libraries like material-ui or react-toolbox provi ...

Implementing CSS keyframes when a specified PHP condition is satisfied

I am looking to implement an opening animation on my website that should only play when a user visits the site for the first time. I want to avoid displaying the animation every time the page is reloaded, so it should only run if a cookie indicating the us ...

An error stating that "DataTable is not a recognized function" occurred within the document function

Previously, I set up datatables using the code below: $(function () { $('#keywords-table').DataTable({ "ajax": ({ url: "{{ route('getKeywordsByProductId') }}", method: "get", ...

Exploring the World of React Variables

Recently, I've been diving into the world of React and encountered some challenges while styling my components. Personally, I find it more organized to style within the same JavaScript file instead of having a separate one. However, I'm curious a ...

Trouble arises with the jQuery keydown function

Currently, I am encountering an issue with a straightforward jQuery code implementation. In addition to the problem description, I have included the HTML structure below, The current functionality works as expected in setting focus on the input field upo ...

Improving Modal Closure on Form Submission Suggestions

Seeking Assistance with Modal Closure After Form Submission I understand that this inquiry may have been posed by someone else before, but I require guidance specifically for my code pertaining to handling form submission with AJAX. As a newcomer to AJAX, ...

Sending a parameter from a click event to a function

Struggling with a jQuery and AJAX issue all night. I am new to both and trying to implement something similar to this example. I have an edit button with the ID stored in a data-ID attribute. Here's an example of what my button looks like: <butto ...

Troubleshooting a unique CSS problem on an Android PhoneGap

We are currently working on an Android application using PhoneGap, HTML, CSS, and jQuery Mobile. After compiling the application in Eclipse, everything seems to work correctly. However, I am facing an issue where my CSS styles are not updating when recompi ...

MUI enables the creation of a fixed vertical box anchored at the bottom of the screen

I’ve attempted the following so far: import "./styles.css"; import { Box, Typography } from "@mui/material"; import styled from "@emotion/styled"; export default function App() { const MainStyle = styled("div")(( ...