Sliding with jQuery to eliminate a div element

I wanted to dive into jQuery and decided to recreate the slick animation from Jay-Z's new album commercials. In these ads, a bar slides left over his name while simultaneously disappearing. I also wanted to add a flashing effect by fading out, fading in, and then fading out the text before it disappeared completely. Can anyone assist me with this? I've managed to set up the layout but can't seem to get the jQuery functions working correctly.

<!DOCTYPE html>
<html lang="en">
<head>
<title>Magna Carta</title>

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        $('#bar').delay(800).css('padding-left', 0+'px');
        $('#main p').fadeOut('slow' function(){
            $('#main p').fadeIn('slow' function(){
                $('#main p').fadeOut('slow');
            });
        });
    });
</script>

<style type="text/css">
body {
    background-color:#f2f2f2;
    margin:0px;
    padding:0px;
}

#main {
    width:300px;
    height:200px;
    position:absolute;
    left:50%;
    top:50%;
    margin:-150px 0 0 -150px;
    text-align:center;
}

#main p {
    font-family:Admisi Display SSi;
    font-size:64px;
}

#bar {
    padding-left:180px;
    height:25px;
    background-color:black;
    position:absolute;
    z-index:2;
    margin-top:87px;
    margin-left:61px;
}
</style>
</head>
<body>
     <div id="main">
         <center>
             <div id="bar"></div>
         </center>
         <p>JAY-Z</p>
     </div>
</body>
</html>

Answer №1

In order to achieve the desired effect, it is necessary to utilize the animate function in this scenario. Previously, simply setting the padding-left to 0 would result in an immediate change. Additionally, ensure that the fadeOut and fadeIn callback functions are corrected:

 $(document).ready(function () {
        $('#bar').delay(800).animate({
            'padding-left':0
        }, 1000, function () {
            // Animation complete.
            $('#bar').delay(800).css('padding-left', 0 + 'px');
            $('#main p').fadeOut('slow', function () {
                $('#main p').fadeIn('slow', function () {
                    $('#main p').fadeOut('slow');
                });
            });
        });
    });

Check out the demonstration here: http://jsfiddle.net/BjBry/1/

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

Instructions for adding a select dropdown feature in Angular 6 that includes a search filter. Additionally, tips on how to filter objects by their name property

I need to add an auto-complete feature in my Angular 6 app where the data is displayed as objects in a dropdown and filtered as we type. **template.html** <mat-form-field > <input matInput [matAutocomplete]="auto" [formControl]="customerFi ...

Switching between two states of a single 'td' element within a column

I am trying to implement a feature where only specific elements in the fourth column of a four-column table toggle when clicked. For example, clicking on an element in the fifth row third column should toggle the corresponding element in the fifth row four ...

Do you mean using a JSON object as a value?

When creating a JSON object where the value itself is an object, what is the correct way to write it? var data ='{"phone":{"gtd": "080"}}'; OR var data ='{"phone":"{gtd: 080}"}'; This question may seem straightforward. I am curious ...

The functionality of React-router-dom protected routes seems to be malfunctioning

Understanding Protected Routes in React.js: While looking at the implementation of protected routes, you may notice that 'false' is being directly used in the if statement. However, even with this condition, the page is still accessible. Why doe ...

Eliminate repeated elements in a selection using an AngularJS custom directive

I am in the process of creating an events app that utilizes JSON data from Drupal to showcase events using AngularJS within a Drupal module. One of the keys in the JSON object is 'genre', which I'm utilizing in a select dropdown to allow use ...

Capture all Fetch Api AJAX requests

Is there a way to intercept all AJAX requests using the Fetch API? In the past, we were able to do this with XMLHttpRequest by implementing code similar to the following: (function() { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.p ...

`Angular RxJS vs Vue Reactivity: Best practices for managing UI updates that rely on timers`

How can you implement a loading spinner following an HTTP request, or any asynchronous operation that occurs over time, using the specified logic? Wait for X seconds (100ms) and display nothing. If the data arrives within X seconds (100ms), display i ...

A growing flexbox container that expands to a specific height before allowing for scrolling

In the case of a fixed height container with two vertical divs, I am aiming for the first div to be as tall as its content, up to 80% of the parent div's height. After that point, the content within the first div should scroll. The second div will the ...

The React/Redux bundle.js file is overly large and bloated

I am currently working on a React project, and the bundle.js file generated by Webpack is quite large at 6.3Mb. I am looking for ways to reduce this size to less than 2.0Mb (though 2Mb would still be acceptable). The full source code can be found on Github ...

The image fails to display when using THREE.js and Panolens.js

Trying to create a 360-degree environment with informational buttons using THREE.js and Panolens.JS However, I'm unable to resolve why the image is not appearing. Continuously encountering the error: Uncaught ReferenceError: process is not defined. ...

Retrieving AJAX content once it has finished loading

Apologies for my poor English. I have a function to handle ajax requests like this: $(document).on("click", ".ajax", function(e){ //dynamic content here, getting the href value from links. }); Now I need to manipulate the content of the ajax response AF ...

I am experiencing an issue where tapping on the Status Bar in MobileSafari is not functioning correctly on a specific

I am struggling to troubleshoot this problem with no success so far. The HTML5 JavaScript library I'm developing has a test page that can display a large amount of output by piping console.log and exceptions into the DOM for easy inspection on mobile ...

Utilizing ajax for fetching a data table

I am new to using ajax and have successfully retrieved data from a table. However, I am now trying to pull in an entire data grid but not sure how to achieve this. In my index.php file, I have the following code: <html> <head><title>Aj ...

What is the best way to utilize XPATH effectively within scrapy?

Explore more here Check out this link too: https://i.stack.imgur.com/8bhzV.png If you are struggling with finding the red marked box number, take a look at the image on this link: https://i.stack.imgur.com/mca05.png Don't worry, I have provided my ...

Accessing properties in JSON data with AngularJS

I am experiencing issues with accessing a JSON object returned from an $http call in my AngularJS app. I have provided the code snippet below, but it seems that nothing is being rendered on the HTML. Can anyone please assist me in identifying what I might ...

Is it possible to utilize Angular's structural directives within the innerHtml?

Can I insert HTML code with *ngIf and *ngFor directives using the innerHtml property of a DOM element? I'm confused about how Angular handles rendering, so I'm not sure how to accomplish this. I attempted to use Renderer2, but it didn't wor ...

The request is not functioning as expected for some reason

My current challenge involves retrieving photos from Instagram using a GET request. I attempted to use jQuery.get(), which has been successful for other types of GET requests but not for Instagram. Despite trying to switch to jQuery.getJSON(), the issue pe ...

The express.js and passport.js middleware in my application are functioning properly and executing as expected, however, there seems to be an issue with the

I have been working on developing a node/express server and decided to implement passport-local for user authentication using a local MongoDB server. I am encountering an issue where the page does not redirect as expected after submitting the login form wi ...

Using AngularJs, you can access the document.body.onfocus event within the controller of

I am attempting to detect when the user closes or cancels the File Upload Window <input type="file"> Since there isn't a built-in listener for the close event of the file upload, I am trying to capture it using the document.body.focus event, s ...

Adding a stylesheet dynamically to the <head> tag using $routeProvider in AngularJS

Is there a way to load a specific CSS file only when a user visits the contact.html view on my AngularJS application or site? I came across this helpful answer that almost made sense to me How to include view/partial specific styling in AngularJS. The acce ...