"Utilize jQuery to animate several elements from the center to the top of the page

I am attempting to shift AlwaysVisibleControls from the center of the screen to the top of the page after a short delay.

Here is the code I have:

$(document).ready(function() {
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded)
});

var ScrollTopTimeOuts = [];
function PageLoaded(sender, args) {
    $('.PanelNotificationBox').click(function () {
        $(this).fadeOut('slow', function () {
            $(this).remove();
        });
    });

    while (ScrollTopTimeOuts.length != 0) {
        clearTimeout(ScrollTopTimeOuts[ScrollTopTimeOuts.length - 1]);
        ScrollTopTimeOuts.length--;
    }
    ScrollTopTimeOuts[ScrollTopTimeOuts.length] = setTimeout(function () {
        $('.PanelNotificationBox').animate({ top: 0 }, 'slow');
    }, 3000);
}

This solution works, but an issue arises when there are multiple notifications (

$('.PanelNotificationBox').size()>1
). In this case, they overlap after the animation.

Q: How can I animate elements so that the first notification is on top and subsequent ones stay relative to each other?

Edit: When I placed the notification divs inside a container div and attempted to animate the container, no animation occurred. Below is the generated HTML/CSS (note: the outer div is within an UpdatePanel):

<div id="ctl00_UpdNotifier"         
    <div style="top: 0px;" id="ctl00_Notifier1_PnlNotification" class="NotificationContainer">
        <div style="left: 292px; top: 398px; display: none; visibility: visible; position: absolute; cursor: pointer; opacity: 1;" id="ctl00_Notifier1_InfoMsg2" class="PanelNotificationBox PanelInfo AutoHide" title="click to close notification">
            <span>Test-Notification(Info)</span>
        </div>
        <div style="left: 292px; top: 463px; visibility: visible; position: absolute; cursor: pointer; opacity: 1;" id="ctl00_Notifier1_ErrorMsg1" class="PanelNotificationBox PanelError" title="click to close notification">
            <span>Test-Notification(RMA-Error)</span>
        </div>
    </div>
</div>

CSS-File:

.PanelNotificationBox 
{
    visibility:hidden;
    z-index:9999;
    width: 50%;
    font-weight: bold;
    font-size:small;
    border: 1px solid;
    margin: 10px auto;
    padding: 20px 20px 20px 60px;
    background-repeat: no-repeat;
    background-position: 8px center;
    box-shadow: 2px 2px 3px #3A4F63;
    border-radius: 4px;
}


.PanelInfo {
    color:Black;
    background-color: InfoBackground;
    background-image: url('../images/info-icon.png');
}

.PanelError {
    color:White;
    background-color: red;
    background-image: url('../images/error-icon.png');
}

Answer №1

To optimize your message display on the page, I recommend placing all messages within a div element and positioning it absolutely at the top of the page. You can then animate this div to showcase all the messages sequentially. By organizing your elements within this div, they will automatically arrange themselves in sequence.

<style type="text/css>
.CustomContainer {
    position:absolute;
    left:10px;
    top:10px;
    width:230px;    
}   
</style>

<div id="CustomContainerID" class="CustomContainer">
    <div>First element</div>
    <div>Second element</div>   
    <div>.... next elements</div>
</div>

Here is an example of how you can implement this using JavaScript:

$(document).ready(function() {
    Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(PageLoaded)
});

var ScrollTopTimeOuts = [];
function PageLoaded(sender, args) 
{
    // Function for individual message close
    $('.PanelNotificationBox').click(function () {
        $(this).fadeOut('slow', function () {
            $(this).remove();
        });
    });

   clearTimeout(ScrollTopTimeOuts);

   // Animate the container after 3 seconds
   ScrollTopTimeOuts = setTimeout(function () {
       $('#CustomContainerID').animate({ top: 0 }, 'slow');
   }, 3000);
}

Answer №2

After trying out the suggestions from @Yoshi and @Aristos, I discovered that they both had a flaw of disrupting the AlwaysVisibleControls js-functionality. Despite this setback, I appreciate their input :)

In the end, I came up with a solution that is functioning well (minus the timer aspect):

var first=$('.PanelNotificationBox:first');
$('.PanelNotificationBox').each(function (index) {
    $(this).animate({ top: '-=' + first.offset().top }, 'slow');
});

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

Interacting with a RESTful API in Xamarin.Forms mobile app and other devices within the shared network

I am currently facing an issue with connecting my Xamarin.Forms mobile application to a RESTful API that I am hosting locally on my computer. The setup involves using Visual Studio for both the Xamarin.Forms mobile application and the API, with the API spe ...

Designing the button outline variant with Material-UI styling

I've recently started using Material UI and I'm facing some difficulties. One of the challenges I'm encountering is with a button component export default function TheButton(props: PropsWithChildren<Props>) { const { className, hover ...

Guide to using Javascript to dynamically insert items into the shopping cart menu list

Greetings! I am diving into the world of JavaScript and currently facing a challenge while working on my eCommerce website project to enhance my web development skills. My query pertains to creating a dynamic system where, upon a user adding items to their ...

problems with hovering over radio buttons in Internet Explorer 9

Encountering a curious issue in IE9: When hovering over my top level wrapper div, the first radio button seems to be triggered as though it's being hovered over. This means that even if the last radio input is selected, clicking anywhere within the wr ...

One-time PHP form submission only

On my website, I offer a variety of PDF download options. To access these downloads, I encourage visitors to sign up using a form. After signing up, they receive a direct link to the chosen PDF in their email. My goal is to streamline the process so that ...

How can JavaScript be used to modify the locale of a web browser?

Is it possible to programmatically set the window.navigator.language using AngularJS? I am exploring different methods to achieve this. At the moment, I rely on a localization service to handle my i18n localization switching. ...

Full replacement of a cell within an HTML table

I have a scenario like the following: <table id="myTable"> <tr> <td class="1">cell 1</td> <td class="2">cell 2</td> </tr> <tr> <td class="3">cell 3</td> &l ...

Removing the hash symbol in Angular: A step-by-step guide

My experience with AngularJS is new, and I am currently working on removing the # from the URLs without utilizing NODE or Express. The project is being hosted locally on MAMP, with index.html acting as the main entry point. Within the structure, there are ...

Issues arise with Promises in nodejs when the process exits before waiting for child processes to complete

I am a beginner when it comes to working with Promises, and I'm aware that my code is not correct (as I still don't completely understand how Promises function). Based on the code provided below, my expectation was that process.exit(0); would on ...

Encountering an issue when trying to input special characters with Entity Framework

When I try to input special characters into SQL Server using Entity Framework, I encounter an error on the server. I have a single database hosted on two servers - one is Localhost and the other is a hosting server. The code runs without any issues on Lo ...

CSS: Experimenting with creating a hover effect that lifts the box upwards

Hey there! I'm currently working on adding a red hover box for my Menu. The issue I am facing is that the hover box is displaying below the menu line. I am attempting to adjust the hover box to move a bit higher or up. You can view the image here: ht ...

Learn to send a dynamic query string from PHP using AJAX for displaying results in a pop-up window

I am trying to implement a feature where PHP dynamic query strings are passed using AJAX, and the response is displayed in a modal box or pop-up. Below are the codes that I have attempted so far. My goal is to pass the dynamic URLs and display the result ...

Unable to modify an image with the combination of HttpHandler, UpdatePanel, and Timer

I'm currently working on implementing a HTTPHandler in ASP.NET to display an image that updates every 5 seconds. The HTTPHandler I have created renders the current time into a Bitmap. On the ASPX side, the Image is nested inside an AJAX UpdatePanel an ...

Ways to create animation solely using CSS for a div element

After spending hours searching for solutions, I still haven't found the perfect answer without using JQuery. I am attempting to add a slide-up animation effect to my divs. I have tried numerous options, including the simplest one: transition: all li ...

Access my account on the one.com control panel using the identical login credentials

I am curious if it's possible to implement a login page on my website for customers and then seamlessly redirect them to the control panel on one.com without requiring them to re-enter their username and password? Visit the action page on one.com her ...

Can you identify a sort event specifically for items that have been updated but not deleted?

I'm working with two lists that are connected $('#list1').sortable({ update: function(event, ui){ //Executing specific code only when an element is reordered }, remove: function(event, ui){ //Performing another action when an ...

Validation of forms using AJAX

I have implemented form validation and an insert query through ajax, which is working correctly. However, if the email already exists, the user should be redirected to another page. Here is my index.php code: <div id="wrap"> <!--wrap start--> ...

The update in state is not reflected immediately by setState, instead, it is rendered after subsequent state changes

I've been diving into React by following this informative video tutorial. However, I encountered an issue while trying to add a new object to the state array that contains all the tasks in my to-do list app. The changes were not being immediately rend ...

A step-by-step guide on building an interactive settings page for your Chrome extension

I am looking to develop an options page that features dynamically generated options. My goal is to extract data from a web page's source using my content script and then display this data on the options page. How can I effectively transfer this data ...

String validation using regular expressions

Below is the code I am using to validate a string using regular expressions (RegEx): if(!this.validate(this.form.get('Id').value)) { this.showErrorStatus('Enter valid ID'); return; } validate(id) { var patt = new RegExp("^[a-zA- ...