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

Integrating draw2d into Mean.js: A Step-by-Step Guide

I'm new to the MEAN Stack and I'm having trouble with something that seems pretty basic. My issue is trying to inject a new instance of draw2d from their downloadable library. The error message I keep receiving is: "Uncaught Error: [$injector: ...

most effective method for recycling dynamic content within Jquery mobile

My jQuery mobile app has a requirement to reuse the same content while keeping track of user selections each time it is displayed. I have successfully created the necessary html content and can append it to the page seamlessly. The process goes something ...

difficulty encountered when transmitting data via ajax to an express server

Just starting out with backend and ran into an issue when trying to send data using vanilla ajax to my express server. Can anyone spot where I might be making a mistake? Here is my ajax request: var xhttp = new XMLHttpRequest(); xhttp.onload ...

ng-if directive does not show data in AngularJS

I have a dynamic collection of images and videos that I want to display one at a time. Specifically, when I click on an image ID, I want it to show the corresponding image, and when I click on a video ID, I want it to show the relevant video. Below is the ...

Learn the process of utilizing ng-class within ng-repeat to designate a specific class for individual iterative div elements

**On my homepage, I am displaying data retrieved from a MySQL database in cards. However, all the tags have the same color i.e. class="tag tag-pill tag-danger". To resolve this issue, I am using ng-class={{hos.class}} where class is a ...

Picture not displaying properly in alternative browsers

While working on a simple website using html and css, I encountered an issue where my logo was not displaying for users on different browsers. Here is the image description Below is the HTML code: <section id="header"> <div class=& ...

Using jQuery to create a dynamically moving div that forms an endless wall

In order to create a continuous wall that pulls text from a database and displays it, I've developed the following code: $(function() { var x = 0; var y = 100.0; var z=0; setInterval(function() { x -= 0.1; y -= 0.1; ...

Improving the functionality of a custom directive in Angular with form validation

Although this question has been raised before, I am still struggling to implement the provided answers into my specific issue. My problem revolves around a tri-state boolean directive in Angular. I am uncertain about how to incorporate validation states in ...

The console is displaying a null value outside of the block, however, the correct value is returned when

I am having an issue where the first console.log() is not returning the correct value, but the second one is. Can anyone provide assistance with this problem? angular.module('resultsApp', ['ngCookies']) .config(['$qProvider&a ...

I am looking to display multiple divs sequentially on a webpage using JavaScript

Looking to display a rotating set of alerts or news on my website. The goal is to show each news item for a certain number of seconds before moving on to the next one in line. However, I'm new to javascript and need help creating a code that will cont ...

JS client-side form validation involves communicating with the server to verify user input

I currently have an HTML form that is being validated on the client side. Below is a snippet of the code: <form id='myForm' onsubmit='return myFormValidation()'> ... </form> Now, I want to incorporate server-side valida ...

Choose the offspring of an element using jQuery

Currently, I have a function set up to open a modal dialog and populate it with information from the 'dblclicked' node: $(function(){ $(".delete").live('dblclick', function () { var id = $(this).attr('id'); ...

Using Puppeteer and Scrapy, this innovative Web Crawler with Scraper combines the power of both

As a newcomer to web technologies, I am faced with the task of crawling and scraping numerous websites that utilize a combination of React, JavaScript, and HTML. These sites collectively contain approximately 0.1 to 0.5 million pages. My plan is to use Se ...

Tips for converting the ng-model value to uppercase in order to validate it

<div class="form-group" ng-class="{'active': field == 'country', 'has-error has-feedback' :Country.$invalid && submitted}"> <label class="col-xs-2 control-label muted" for="Country">Country</labe ...

Avoid navigating to a different page in AngularJS when clicking a button with the ng-click function

Despite my best efforts, I am unable to get any response when clicking on the button. The next page fails to open as intended... HTML <button class="button button-small button-block button-positive sign-up" type="button" nam ...

background image alteration when scrolling

I've been attempting to change the background image on scroll, but I haven't had any luck finding a guide. So, I'm hoping someone here can help me out. I found a video that showcases exactly what I'm trying to accomplish - https://www.y ...

Issues with AngularJS binding not functioning properly within JSFiddle

When I make a jsfiddle page: jquery datatable with Angularjs - individual column searching none of the angularjs bindings seem to be functioning properly, as it only displays {{n1}} instead of showing the expected bound content. The external resource ...

Issue with sending an ajax post request using Jquery

The jquery ajax request below is not working as expected: $(document).ready(function(){ var friendrequest = $(".friendrequest").val(); $(".afriendreq").click(function(){ $(".afriendreq").hide(); ...

How can I prevent duplicate IDs when submitting a form through AJAX within a while loop?

While submitting a form using Ajax within a while loop, I encountered an issue where the same form ID is being used multiple times due to the loop. As a result, the form only submits once. I believe that I need to generate a unique ID for each iteration of ...

Creating a transparent background in a three.js canvas: a step-by-step guide

I came across a wave particle animation on Codepen (https://codepen.io/kevinsturf/pen/ExLdPZ) that I want to use, but it has a white background. However, when I try to set the body background to red, it doesn't show up once the canvas is rendered. I ...