The animated GIF fails to initiate its animation upon being displayed

I am facing an issue where I cannot get an animated GIF to start playing after a button click. The image displays correctly but the animation does not start. I have tried various techniques like wrapping it with a div, using SetTimeOut, etc., but none of them seem to work consistently on both laptops and mobile devices. Some methods work on laptops but not on mobile devices, like setting a timeout in JavaScript. Below is the code snippet. Can you help me figure out how to make it work on both laptops and mobile devices:

<script>
function AnimateGif() 
{           
$("#anim_upload").css("display", "");
}
</script>

<asp:ImageButton CssClass="uploadedFile_btn" runat="server" ImageUrl="icon-upload2.png" ID="uploadedFile" OnClick="Button1_Click1" OnClientClick="AnimateGif();"/></div>

<img alt="" src="anim_upload.gif" id="anim_upload" style="display:none" />

LAPTOP solution

The following code works fine on laptops, but unfortunately, it doesn't work well on most mobile devices. I am curious about the reason behind this inconsistency.

<script>
function AnimateGif() 
{           
setTimeout('document.getElementById("anim_upload").style.display = "block"', 200);    
}
</script>

Answer №1

When using asp:ImageButton and implementing the OnClientClick to handle a JavaScript call, keep in mind that clicking this button will trigger the JavaScript function but also cause the page to refresh. During the refresh, any gif animations on the page may not play properly due to a browser issue. To resolve this, you can add a simple return false statement to your JavaScript function like so:

OnClientClick="return AnimateGif();"
-- In your aspx code.

The corresponding JavaScript function would look something like this:

function AnimateGif() 
{           
   $("#anim_upload").css("display", "block");
   return false;
}

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

Can someone provide guidance on creating a JavaScript function that locates an image within an <li> element and sets that image as the background-image property in the li's CSS?

Let's dive deeper into this concept: <li class="whatever"> <img src="/images/clients/something.jpg"> </li> <li class="whatever"> <img src="/images/clients/whatever.png"> </li> He ...

Every Dynamic Post automatically defaults to the initial object

I am currently developing an app that retrieves feeds from a Wordpress site and displays individual posts in a jQuery mobile list format. Here is the JavaScript code I am using: $(document).ready(function () { var url = 'http://howtodeployit.com/ ...

What is the best method to close a polygon infowindow when hovering over a map marker?

I am currently working on integrating Google Maps which includes a set of polygons representing state boundaries and markers representing cities within each polygon. I want to display information when hovering over a polygon/state. My question is: how can ...

Using jQuery Mobile alongside two distinct versions of jQuery

My current task involves inserting both jQuery and custom JavaScript into the DOM of an existing page. The jQuery is inserted right before my script, where I utilize window['my$'] = jQuery.noConflict(true);. This approach worked smoothly after ...

Enter key triggering input change event is unresponsive in Internet Explorer

$("#inputBoxWidth").change(function() { var curValue = $("#inputBoxWidth").val(); alert(curValue); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form> <input type="text" id="inputBo ...

Updating the default date in Bootstrap datetimepicker can be done through the use of a Bootstrap modal. Here

How can the default date value be updated when using datetimepicker within a bootstrap modal and displaying both datepicker and time picker inline? The issue is that the datetimepicker value updates on the first click after refreshing, but on the second cl ...

Is it possible for an absolutely positioned element to have floating elements wrapping around it?

Within my content box (#left-home-content), I have a series of paragraphs followed by a link in a <span> tag (.read-more-link), and then a <div> tag (#left-home-spread) that needs to be positioned absolutely at the bottom of the box. This may s ...

Removing a specified div using Jquery

<div id="a_all"> <div>&nbsp;&nbsp;&nbsp;&nbsp<input type="checkbox" name="m_a">1</input<br></div> <div>&nbsp;&nbsp;&nbsp;&nbsp<input type="checkbox" name="m_a">2</input< ...

Analyzing transaction volumes using Bing Maps integrated with asp.net postbacks

Check out this resource on Bing Maps Transactions by API: Bing Maps Transactions by API I am currently using the Bing Maps web control on an ASP.NET web forms page. I have a query regarding the duration of a session, as it mentions that it will end when t ...

Ensure that two div elements always expand to occupy the entire width of the parent div container

Despite my research and understanding of floats, I am struggling to comprehend why I am unable to evenly float two divs within a wrapping div. #wrap { border: 1px solid red; height: 200px; width: 100%; } #gr1 { border: 1px solid blue; ...

The JavaScript-generated form element will not be included in the data submitted through the POST method

While it may appear that this question has been asked before, my specific inquiry seems to be unique as I have not found a similar answer in other threads. Therefore, I am initiating a new discussion. My issue revolves around a form which contains a link ...

Sort table rows by checkbox value in javascript

Is there a way to use javascript or JQuery to group the rows in this table by Office or Age based on the checkbox option selected? For example, if the Office checkbox is checked, the table rows should be grouped by Office. If the Age checkbox is checked, ...

Steps to implement a print modal with JavaScript, jQuery and more

Imagine having a print button on several pages that, when clicked by the user, triggers a modal to pop up with the content for printing. Any suggestions or ideas would be greatly appreciated. I have multiple pages with a print button. When the user clicks ...

Navigating through Data Items Using ListView in Select

Creating a custom file manager in asp.net. The functionality involves clicking on a folder within a TreeView control, which then displays the files contained in that folder in a ListView control. Customization of the ListView <asp:listview id="lvFile ...

Tips for tallying unique data points in JSON structures

json file {"people":[{"Name":"Ray Parker","Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94f8e1f7e0e1e7baf1e0bae1f8e0e6fdf7f1e7d4faf5e0fbe5e1f1baf7f5">[email protected]</a>","State":"Wyoming","Country":" ...

Displaying three lists side by side in a web application can be achieved using a combination of jQuery Mobile and the Model-View

Having trouble setting up three lists to display side by side in jQuery Mobile? Unfortunately, the ui-grid won't work for me because of a script that hides them and reveals them based on a number from 0-3. Each list should be dynamically centered and ...

Is it possible to assign a Bootstrap class as a variable in a custom CSS declaration?

While trying to make my website responsive, I planned on using media queries to adjust text size and other elements. The issue arises because I rely on bootstrap for setting text sizes. Is there a way to apply bootstrap classes in my CSS file? For instanc ...

Is it possible to adjust the background color based on the current time of day?

I have successfully designed a visually appealing website using HTML5, CSS, and Bootstrap. I am interested in finding a way to automatically change the background color and navigation bar selection color based on the time of day - blue during the day and d ...

Utilizing jQuery to enable a div to follow the touchmove or mousemove events while also automatically

I am looking to create a basic function in my jQuery script. I want the pages to slide horizontally in response to the movement of a finger or cursor on the screen. While there are many plugins available for this purpose, I prefer a simple, customized solu ...

- Lorem ipsum dolor sit amet, consectetur adipiscing elit

I am looking to create a list with lower-roman indexes that are enclosed in parentheses (ii), where the content of each item is indented. Here is an example: (i) lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer ut metus nec urna ...