Switch the hover effect to be activated by clicking

Recently, I discovered an incredible plugin created by the talented developer janko. It has been a fantastic addition to my project.

The only issue I've encountered is that I do not want the default hover style. Is there a way to transform it into a clickable tab instead of a hovering tab? Any guidance on how to achieve this would be greatly appreciated. Thank you in advance...

Answer №1

Upon reviewing the demonstration available at http://www.jankoatwarpspeed.com/examples/AdvancedDocking/, you will come across this particular section of code:

$("#dock li").hover(function(){
            $(this).find("ul").animate({left:"40px"}, 200);
        }, function(){
            $(this).find("ul.free").animate({left:"-180px"}, 200);
       });

The suggested modification is as follows:

$("#dock li").click(function(){
    if($(this).find("ul").css("left") != "40px")    {
    $(this).find("ul").animate({left:"40px"}, 200);
}
else
{
    $(this).find("ul").animate({left:"-180px"}, 200);
}
});

Transitioning from hover to click (or utilizing toggle) is advised. Additionally, certain CSS adjustments are required:

Eliminate:

#dock > li:hover ul {display:block;}

Replace display:none with display:block

#dock > li ul {position:absolute; top:0px; left:-180px;  z-index:-1;width:180px; display:block;
                   background-color:#F1F1F1; border:solid 1px #969696; padding:0px; margin:0px; list-style:none;}   

Answer №2

To make it work, simply switch the "hover" to toggle.

$("#dock li").toggle(
    function()
    {
        $(this).find("ul")
               .animate({left:"40px"}, 200);
    }, 
    function()
    {
        $(this).find("ul.free")
               .animate({left:"-180px"}, 200);
    });

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

Accessing elements in AngularJS through ng-click function

According to information provided in this answer, it is necessary to pass the $event object to the ng-click function in order to access the target element. $scope.setMaster = function(obj, $event){ console.log($event.target); } Although using event.t ...

Choosing identical elements within comparable sub-divisions

How can I use JQuery to select an array of elements that are in separate sub divs? For example: <div class="panelWrap"> <div id="dvStage1" class="milestoneWrap" runat="server"> <div class="grid_1 ...

Leveraging JQuery for Inserting Data Into mySQL Database

As I delve into JQuery for the first time while working on a project, I realize that this endeavor serves as more of a learning experience rather than a functional one. Currently, I have three PHP files in play: 'connection.php', which establishe ...

Transforming a single object into several arrays

I have a JSON file called "icon.json" that contains the following data: [ { "name": "happy", "url": "1.gif" }, { "name": "excited", "url": "2.gif" }, { "name": "surprised", "url": "3.gif" ...

What is the proper way to include a parameter in an ASP onclick function within a table row?

Below is a table row declared within a listview: <tr onclick="<%= _jsPostBackCall %>;" /> When calling a postback method on the backend, I need to retrieve the tr index: public void RaisePostBackEvent(string eventArgument) { ...

Filling a blank table using jQuery

I am attempting to search for an item by sending a GET request to my service and then populating my table with the response, but I am struggling to achieve this with my current code. $(function(){ var $searchInput = $("#search"); $("#searchOptions").c ...

Passing a value from an HTML template to a method within an Angular 4 component

Encountering an issue with Angular 4. HTML template markup includes a button: <td><a class="btn btn-danger" (click)="delete()"><i class="fa fa-trash"></i></a></td> Data is assigned to each td from a *ngFor, like {{ da ...

Adjusting the sidebarPanel height to match the mainPanel content in a shiny app

I'm currently developing an app that features a scrollable sidebarPanel alongside a mainPanel that can have varying heights, such as: library(shiny) ui <- fluidPage( headerPanel('Iris k-means clustering'), sidebarPanel(style = " ...

How to prevent multiple JQuery mouseenter events from firing when divs are overlapping

Currently, I am using the JQuery mouseenter event to display a smaller DIV B inside another DIV A. However, I am facing an issue where when I hover over DIV B, the mouseenter event gets triggered again. What I actually want is for DIV B to be shown and hav ...

What is the best way to modify an image in a column when I hover over a table row that was dynamically inserted using a button function?

Is there a way to dynamically change an image in a column when hovering over a table row that was added through a button function? Here is the current code that I am using, but it does not seem to work as intended when I hover over the row. This function ...

Creating transparent overlay boxes with CSS grid

I'm working on a design where I need to display text information over an image. The challenge is aligning the text properly, especially when the screen size changes due to using a grid system (1140). Currently, I have a div with transparent background ...

Codeigniter - Ajax request successful in remote server but fails in local server

I am encountering an issue with my web application that makes Ajax requests to a server using Codeigniter-php code. While the Ajax requests work fine on the local server, they do not function properly when the application is hosted on a remote server. The ...

What is the source of these additional pixels that appear when percentages are used for defining height?

I have been working on implementing a sticky footer that I've successfully used in the past for various websites. You can find the link to the original method here: However, this time I am facing a challenge as I want to make the footer more responsi ...

Using jQuery to trigger a change event and then chaining it with an AJAX

I've implemented a chained select feature which is working quite effectively. $(function() { /** * Chained Select (id_foo) * * @method on change */ $('select[name="id_foo"]').on('change', function() { var id ...

What is the best way to extract information from a JSON file and display it on a webpage using

I am new to this and I have a question for everyone Here's an example of the JSON response from my URL: The JSON data returned is as follows: { "Data":{ "id": 1312, "Name": "Steem Dollars", "Symbol": "SBD", "website_slug": "steem-dollars", "Level": ...

What is the best way to retrieve the responseText using the jQuery.getJSON method within JavaScript?

I am currently facing an issue where I am attempting to retrieve information from a JSON file located in my directory by utilizing the jQuery.getJSON method. Unfortunately, when I try to access the object shown in the image, I am unable to extract the resp ...

Using jQuery to efficiently handle dynamically added elements by combining the ".on" and ".each" methods

I am currently in the process of dynamically inserting new elements into my page, and these elements have a specific structure that is represented as follows: <div id="cars"> <input type="text" name="car_added[]" class="car" /> <inp ...

What is the best way to remove headers and footers programmatically in print pages on Safari using JavaScript?

Struggling with eliminating the header and footer on print pages in Safari using JavaScript? While disabling the header and footer manually can be done through print settings in most browsers, my aim is to automate this process with code to ensure that use ...

Utilizing HTML imports in Typescript for efficient use as TemplateStringLiteral

Recently, I started using TypeScript for the first time and I'm looking to integrate it into my webpack build. Currently, I am working with ts-loader and babel-loader to load TypeScript files while also attempting to include HTML files within the scr ...

How can you resize an HTML table by dynamically adding or removing rows and columns?

Is there a way to dynamically add or remove rows and columns from an HTML table, also known as resizing it? The table should have a rectangular shape as it will later represent a 2D array value. Since the table will be refreshed frequently and may become ...