In Ionic, the performance of ng-show and ng-hide can be less than optimal. This can result in brief instances where two elements are visible

Within my Ionic project, there is an audio player. When the audio is not playing, the user has the option to:

  1. Tap the play button
  2. Start the audio
  3. Hide the play button and show the pause button

Conversely, when the audio is already playing, the user can:

  1. Tap the pause button
  2. Pause the audio
  3. Hide the pause button and show the play button

The problem arises when both the play and pause buttons briefly appear at the same time. This issue occurs only on iOS when tapping the pause button while audio is playing, as Android does not experience this glitch.

This is a visual representation of the error:

https://i.sstatic.net/lKTQ1.gif

The HTML structure for the buttons is as follows:

<span ng-click="player.playAudio(audio)" ng-hide="player.isViewAudioPlayingAudio()">
    <img src="img/audio-play-icon.svg" alt="" class="big-icon audio-control">
    <img src="img/audio-play-hover-icon.svg" alt="" class="big-icon audio-control-hover">
</span>

<span ng-click="player.pauseAudio()" ng-show="player.isViewAudioPlayingAudio()">
    <img src="img/audio-pause-icon.svg" alt="" class="big-icon audio-control" >
    <img src="img/audio-pause-hover-icon.svg" alt="" class="big-icon audio-control-hover">
</span>

You can observe the class changes in action here (GIF image, click to open):

https://i.sstatic.net/5baau.gif

The CSS for hover buttons consists of a few lines. While this is unrelated to the issue at hand, I have tested removing the hover images with no improvement. Nonetheless, I have included it for clarity:

.audio-control-hover{
    display: none;
}

.activated{
    .audio-control{
        display: none;
    }

    .audio-control-hover{
        display: inline;
    }
}

Any suggestions to enhance the performance of ng-show and ng-hide?

Answer №1

For certain scenarios, using ng-if results in better performance. Check out this informative article to learn more about why you should consider using ng-if over other options.

Answer №2

When it comes to transitioning between states in Ionic, the framework leverages the angular js animate library. However, this can sometimes lead to issues on iOS devices. To address this, you can try incorporating the following snippet into your CSS code to disable animations:

.ng-hide,
.ng-animate,
.ng-hide-animate,
.ng-hide-remove {
    display: none !important;
}

.ng-animate.no-animate {
    -webkit-transition: 0s none;
            transition: 0s none;
     -webkit-animation: 0s none;
             animation: 0s none;
}

I trust that this workaround will prove beneficial for your project. Feel free to reach out if you have any questions or concerns.

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

The art of combining CSS3 gradients with background images

I've created a function that changes the parent element's background gradient when a checkbox's status is toggled. Check out the Lorem link to see it in action! Click here to view. However, I've encountered an issue with applying this ...

What is the best way to send a selected value to a different function in order to retrieve data from a JSON file based on that

I have been working on writing HTML and JavaScript code to extract data from a JSON file. Here is a snippet of my HTML code: <div class="section"> <div class="sectionTitle"> <h3>Configuration</h3> </div> &l ...

What could be causing the leftward movement of my hovering image?

I'm seeking a solution for my image overlay text shifting issue. Currently, when I hover my mouse over the image, the overlaid text moves to the left by 69 pixels instead of staying directly above the image. How can I rectify this problem? https://i. ...

Switching back and forth between bootstrap collapse to display server-provided data

I am facing an issue with collapsible sections in my Laravel project that are populated with data from a database: <div class="col col-md-5"> <div class="card"> <div class="card-header text-right"> ...

Tips for enhancing the appearance of the dropdown scrollbar in PrimeNG

Just started exploring Angular and I've been struggling to customize the scrollbar on a PrimeNG dropdown. Does anyone have any tips or tricks to achieve this? Here is the HTML code: <p-autoComplete placeholder="- Select -" (onSelect)="onSelect(dh ...

Sorting in descending order in jquery Datatables does not function properly when using the "order" option

Can someone help me figure out how to order my jQuery datatable? I've been struggling to get the first column to sort in descending order even after using "order": [[0, 'desc']]. You can check out the JS fiddle here. <table id="datatabl ...

toggle switch for numerical input

Whenever the "Qty" radio button is selected, I need to activate an input box that accepts numbers. Conversely, when the "rate" radio button is clicked, I want to disable this input box. This is how I designed it: <input type="radio" class="radioBtn" ...

There seems to be an issue with accessing the Angular module, even though it has been clearly

While attempting to execute the code below, two errors are encountered: Error: [$injector:nomod] Module 'rooms' is not available! The module name is spelled correctly and loaded dependencies have been included. The modules are structured in the c ...

nodemailer failed to authenticate login: 535 Authentication Error

I'm encountering a 535 Authentication Failed error when trying to utilize the nodemailer npm package in my node application for sending emails through the contact page. My email and password are correct, so I'm unsure why this issue is arising. v ...

Challenges arise when dealing with an excessive amount of nested POJO structures

What can I do with complex POJOs tree in my template? For example: <div important-attr="{{item.another_sub_item_three.lets_go_a_little_dipper.property}} " another-important-attr="{{ item.another_sub_item_three.just_one_more.ano ...

Having trouble with updating PHP MySQL data using serializeArray?

My HTML page includes a display of temperature with two buttons - one for updating MySQL with the temperature setting and the other for toggling on/off data. Previously, everything was functioning correctly with the initial code: function myFunction() { ...

Confirm Submission Issue in HTML Form

During my testing of the blacklist confirmation dialog, I encountered an issue where clicking the OK button did not submit the form as expected. Instead, it seemed to be stuck in a loop where clicking the button had no effect and the dialog remained on scr ...

Express and Firebase Function: Headers cannot be set once they have already been sent

My experience has been mainly with the Hapi framework for developing RESTful APIs. However, for my current project, I decided to use Express and I'm encountering some confusion regarding the issues that are arising. While testing the POST endpoint us ...

Different ways to shuffle the arrangement of divs

Forgive me if this seems like a simple query, but I am struggling with it. Essentially, what I want to achieve is to randomize the positioning of the items, where item 1 can adopt the style of item 3 (or 2 or 4), item 2 can take on the style of 1, 3, or 4, ...

The selected rows in Datatables.js do not retain their selection status after calling ajax.reload()

As per the information provided on the Datatables website, the feature "retain row selection over a data reload" should work seamlessly. However, I am facing issues with it when using data from an ajax source. Below is the code snippet showcasing how I am ...

Retain the user's input in the text box even after the form has been submitted

Currently, I am tackling the challenge of creating a register form with an error handler to manage any mistakes made by users during registration. Once the form is submitted, potential errors are displayed to the user. To enhance user experience, I am ex ...

Invisible style date input value on iPhone mobile devices

My goal is to enhance the appearance of an HTML5 input with a custom icon, using a font pack. Although I mention FontAwesome in this example, in reality, I'm utilizing a different custom font pack. On my mobile device (iPhone X), I can see the calend ...

How can UI tests be run in headless mode in Selenium 4 and above?

Selenium recently announced the release of Selenium 4, and they have also mentioned that there will be no support for PhantomJS from Selenium 4 onwards. Does this mean that Selenium no longer supports headless automation, or is there a different method t ...

Looking to ensure that a div with no content adjusts to the height of the neighboring div?

Currently working on a Reactjs project. I'm trying to set the height of the colorTab div to match that of the content div, while making it responsive. The height of content should adapt dynamically based on the text content in title and description, w ...

Conceal a particular row in SharePoint by utilizing JavaScript with jQuery

I'm facing an issue with SharePoint 2010 where the _cts folder is visible in all document libraries. Despite my efforts to research and find a solution, I have been unsuccessful so far. For now, my workaround is to hide the entire row. Here's a ...