AngularJS: Modify Z-Index on Click Event

My current project involves a navigation bar with four items, each accompanied by an icon. These icons are positioned absolutely one behind the other and are loaded into the view from different templates within the same controller.

I am attempting to dynamically change the z-index of the icon based on the clicked menu item using AngularJS. I have experimented with methods like ng-switch, but my lack of experience has made it challenging to find a solution.

If anyone has any ideas or insights on how to resolve this issue, I would greatly appreciate your input.

Thank you in advance!

HTML

Header View:

<nav id="top-nav">
    <ul>
        <li ui-sref="root.home";>Home</li>
        <li ui-sref="root.drinks">Drinks</li>
        <li ui-sref="root.food-and-snacks">Food And Snacks</li>
        <li ui-sref="root.contacts">Contacts</li>
    </ul>
</nav>

Icons View:

<ul>
    <li>Home Icon</li>
    <li>Drinks Icon</li>
    <li>Food Icon</li>
    <li>Contacts Icon</li>
</ul>

CSS

ul li{
    position: absolute;
    height: 50px;
    width: 50px;
    lefT: 0;
    top: 0;
    z-index: 0;
}

Answer №1

Here's how I approached changing the Z-Index when clicked:

HTML

<ul class="icons">
    <li ng-class="{front:ctrl.activeTab(1)}">icon1</li>
    <li ng-class="{front:ctrl.activeTab(2)}">icon2</li>
    <li ng-class="{front:ctrl.activeTab(3)}">icon3</li>
    <li ng-class="{front:ctrl.activeTab(4)}">icon4</li>
</ul>

<ul class="nav">
    <li ng-click="ctrl.selectTab(1)">menu item1</li>
    <li ng-click="ctrl.selectTab(2)">menu item2</li>
    <li ng-click="ctrl.selectTab(3)">menu item3</li>
    <li ng-click="ctrl.selectTab(4)">menu item4</li>
</ul>

CSS

ul.icons li.front{
z-index:1;
}

CONTROLLER

self.selectTab = function (id) {
    self.tab = id;
}
self.activeTab = function (id) {
    return self.tab === id;
}

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

Choosing multiple items using ng-checked and ng-model in AngularJS

I am working with an Ionic application and encountering a minor issue, much like AngularJS. <ion-list class="list-inset subcategory" ng-repeat="item in shops"> <ion-checkbox class="item item-divider item-checkbox-right" ng-model="selectAll" ...

CRITICAL ERROR: CALL_AND_RETRY_LAST Memory allocation failed - JavaScript heap exhausted

I am experiencing issues when trying to search using npm: npm search material However, I keep getting this error message: npm WARN Building the local index for the first time, please be patient FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaSc ...

I am struggling to get the pop-up to close using the current code. I suspect that the issue might be related to the variable I was previously using in WordPress. I have made changes but the pop-up

While delving deeper into the realm of Javascript, I encountered a stumbling block with a single popup intended for the main page of a WordPress website I am constructing. Despite my attempts to modify the code's variables, they seem unyielding. Surpr ...

Enhance the functionality of Woocommerce email notifications by incorporating a customized VAT field

I have exhausted all options and tried various email hooks without success. I inherited an outdated PHP code that was developed by someone else, which I updated for new woocommerce hooks (since the code is 4 years old). Everything is functioning smoothly e ...

Avoiding Overlapping DIVs: Tips to Keep Your Elements in Place

Instead of using table-based layout, I have decided to go with a DIV-based layout in order to streamline the markup and improve page load speed. However, as I am not an expert in CSS, I find it quite challenging. Below are the CSS classes I am currently us ...

Modifying the appearance and behavior of an element dynamically as the page is being loaded using AngularJS

Struggling with a challenge for two days now, I have attempted to implement a panel-box using bootstrap and AngularJS. Within the confines of a controller, my code looks like this: <div id="menu2a"> <div class="panel list-group"> <div ...

Utilizing object property in angular's ng-model directive

After defining a class, instantiating it and assigning the object to scope, I encountered an issue with ng-model references. Despite setting everything up correctly, the code isn't working as expected. I have a hunch that Angular might not be compatib ...

Why are my images only 1 pixel tall in Internet Explorer 8?

<img src="blah.png" width="150" height="auto"> When viewed in Firefox, Chrome, or Safari, the image will appear as intended. However, Internet Explorer may cause the image to display at a height of only 1 pixel while maintaining the width of 150 pix ...

A technique for horizontally centering an image while simultaneously ensuring that the bottom is pushed down, even at an unknown resolution, and maintaining center alignment if

Imagine a scenario where I have an image with unknown resolution. My goal is to horizontally center it, even if the window's width is smaller than the picture, while also adjusting the bottom of the window to match the height of this picture. Is ther ...

jQuery providing incorrect measurements for an element's height

I am encountering an issue with obtaining the height of the #header element in my AngularJS application. Despite using jQuery, the returned height seems to be incorrect. The current code snippet looks like this: $(document).ready(function() { function ...

Creating elegant Select Dropdown Box in AngularJS without relying on images

I am currently working on an angular page and have implemented a dropdown with ng-Options to fetch and set values successfully. However, I am now looking to enhance the appearance of this dropdown. After exploring options like ui-select, I realized that be ...

Incorporating AngularJS 1 into the design of a fresh "foobar" user interface overlay

Currently, I am working with AngularJS 1 along with angular-material and ui-router. Is there a preferred method for implementing a user interface for a new "foobar" feature? For instance, let's say I have a ui.route leading to /app/#/foobars/, which ...

Restrict the Angular ng-repeat directive to specific rows only

Suppose we have a JSON dataset listing all languages of books: $scope.data = [{ "title": "Alice in wonderland", "author": "Lewis Carroll", "lang": ["en"] }, { "title": "Journey to the West", "author": "Wu Cheng'en", "lang": [" ...

Unable to achieve full width for a div within a scrollable container

Currently, I am in the process of constructing a new website using Gatsby.js. However, I have encountered a minor issue with some CSS related to code blocks. Since CSS is not my strong suit, I have been unable to resolve it thus far. Below is a runnable sn ...

What is the best way to add several icons at once?

Is there a way to insert multiple star icons directly below the review text? I attempted to use pseudo elements to add the icons, but I could only insert one icon when I actually need to include multiple icons. Here is what I have tried so far: .review:: ...

Utilizing JQuery slideToggle() to Toggle Between Opening and Closing Multiple Divs

Utilizing Jquery's slideToggle() function to manage the opening and closing of my main menu has been a success. However, I am facing the challenge of making sure that when one div is opened, another one closes. Despite trying various methods, I have ...

Encountered a Webpack issue when trying to load the primeng.min

I recently initiated a fresh project using yo aspnetcore-spa. My goal is to integrate the PrimeNG component library. Upon installing font-awesome and primeng: npm install font-awesome primeng --save I included CSS in the webpack vendor list: vendor: [ ...

Unveiling the Mystery: How Browser Thwarts Server Push in HTTP/2.0

After studying the documentation of HTTP/2.0, I discovered that it is feasible to completely close a referenced stream using the RST_STREAM frame. Check it out here: ()! I am curious about how this feature can be implemented in popular web browsers such a ...

What is the process for incorporating multiple HTML pages into an Ionic hybrid mobile application?

Struggling to combine my sign in and sign up pages into a single index.html page. I'm currently working on a project involving Hybrid mobile app development. ...

Before beginning my selenium scripts, I need to figure out how to set an item using Ruby in the browser's localStorage

Before running my selenium scripts, I am attempting to store an item in the browser's localStorage. I attempted to clear the local storage using this command: driver.get('javascript:localStorage.clear();') This successfully cleared the lo ...