Issues with slideToggle and hover functionality in Jquery

I am currently working on a webpage that showcases team members' photos, along with their descriptions that slide down when clicked. I'm facing an issue where the hover effect for displaying names over the photos does not work in tandem with the JQuery function. Is there a way to make both functions compatible? Your suggestions are highly valued!

Another challenge I'm encountering is the responsiveness of the page layout on mobile devices. The current three-column design for desktop view transitions into a two-column layout for mobiles. However, arranging HTML elements with photos and matching descriptions side by side causes all photos in a row to shift downward. My goal is to keep the photos aligned next to each other within each row. Any insights or recommendations would be greatly appreciated!

Below is a snippet of my HTML (the first photo includes a hover effect while the rest utilize the slideToggle function):

Answer №1

Streamline your HTML:

$('.portfoliowork').click(function(){$('.portfoliowork').not(this).removeClass('active');$(this).toggleClass('active');});
.portfoliowork { overflow:hidden; float: left; margin-left: 5px; width: calc(100% / 3 - 15px); margin-bottom: 200px }
.portfoliowork img { width: 100%; height: auto; }
.portfoliowork p { position: absolute; left:0; display: none; }
.portfoliowork.active p {display: block;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="portfoliowork">
  <img src="http://placehold.it/100x100">
  <p>"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="portfoliowork">
  <img src="http://placehold.it/100x100">
  <p>consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="portfoliowork">
  <img src="http://placehold.it/100x100">
  <p>sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
<div class="portfoliowork">
  <img src="http://placehold.it/100x100">
  <p>eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
    dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>

Answer №2

Instead of showing the name of a person when hovering, it now appears on a click event. You can view the output here: https://jsfiddle.net/nu5mbqcd/2/

To apply this solution, follow these steps:

Step 1: Replace the code below

<img src="images/portfolioph.jpg" class="togglephoto" data-toggleid="toggledesc5">

with

<div class="on-focus clearfix" style="position: relative; padding: 0px; margin: 10px auto; display: table; float: left">
   <img src="images/portfolioph.jpg" class="togglephoto" data-toggleid="toggledesc5" tid="">
   <div class="tool-tip right">Name1</div>
</div>

Step 2: Add the following CSS

.tool-tip{
   color: #fff;
   background-color: rgba( 0, 0, 0, .7);
   text-shadow: none;
   font-size: .8em;
   visibility: hidden;
    -webkit-border-radius: 7px; 
    -moz-border-radius: 7px; 
    -o-border-radius: 7px; 
    border-radius: 7px; 
    text-align: center; 
    opacity: 0;
    z-index: 999;
   padding: 3px 8px;    
   position: absolute;
   cursor: default;
    -webkit-transition: all 240ms ease-in-out;
    -moz-transition: all 240ms ease-in-out;
    -ms-transition: all 240ms ease-in-out;
    -o-transition: all 240ms ease-in-out;
    transition: all 240ms ease-in-out;  
   }

/* tool tip position right */

.tool-tip.right{
    top: 50%;
    right: auto;
    left: 106%;
    margin-top: -15px;
    margin-right: auto; 
    margin-left: auto;
}

.tool-tip.right:after{
    left: -5px;
    top: 50%;   
    margin-top: -6px;
    bottom: auto;
    border-top-color: transparent;  
    border-right-color: rgba( 0, 0, 0, .7); 
}


/* on hover of element containing tooltip default*/

.on-focus img[tid="1"] + .tool-tip{
    visibility: visible;
    opacity: 1;
    -webkit-transition: all 240ms ease-in-out;
    -moz-transition: all 240ms ease-in-out;
    -ms-transition: all 240ms ease-in-out;
    -o-transition: all 240ms ease-in-out;
    transition: all 240ms ease-in-out;      
}

Step 3: Replace the jQuery code with the following code:

$('img[data-char=togglephoto1]')
$(function(){
    $('.toggledesc').hide();

    $('.togglephoto').on('click', function(){
        var toggleid = $(this).attr('data-toggleid');

        if( $('.' +toggleid).is(":hidden")) {
            $(this).attr('tid','1');  
         }
        else {
            $(this).attr('tid','');     
        }
        $('.' +toggleid).slideToggle("slow");

    });

});

I hope this explanation helps you solve your issue.

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

Exploring Object Array values with Javascript

I am working with an Object array and I need to implement a contains filter for every property. This means that the search should look for a specific keyword in any of the properties and return the object if it finds a match. Can you please provide guidanc ...

The app is having trouble loading in Node because it is unable to recognize jQuery

I am currently using Node to debug a JavaScript file that includes some JQuery. However, when I load the files, the $ sign is not recognized. I have installed JQuery locally using the command npm install jquery -save-dev. The result of "npm jquery -versio ...

Identifying when a page is being unloaded through JavaScript

Dealing with a cancel button that triggers an Ajax call and refreshes page content can be tricky when trying to prevent the UI from refreshing during navigation away from the page. One approach is using a global variable within the window object, but this ...

Creating an AJAX URL in an external JavaScript file within a Django project

How can I verify if a student user's email exists in the database using keyup event in a registration form, and prevent form submission if the email is already registered? Below are the relevant files for achieving this: urls.py urlpatterns = [ ...

Sorting tables using jQuery when receiving tables via AJAX requests

I have developed a custom script that enables me to search torrent sites. When the page loads, there is a text area on the left for entering search queries and an empty div on the right. The search functionality utilizes AJAX to fetch search results in the ...

PHP and AJAX collaboration encounters issue with returning JSON data

I'm encountering an issue with the PHP & AJAX login functionality. Upon clicking the Login button, instead of receiving the expected alert, I am redirected to login.php and presented with a JSON response like: {"return":"error"} or {"return":"success" ...

A new map created to restore lost features

As the web developer for my university, I am currently focused on updating our map feature. You can access the site here. The problem I'm facing is that the info windows stopped displaying about two months ago. Despite ensuring that our jQuery is up-t ...

Is there a way to determine if a span includes a particular word?

I am trying to hide a specific element based on the content of another element with a certain class. Here is an example of what I have: <span class="border">0€</span> <div class="pop">something</div> Despite my efforts, the cod ...

Decrease the space between slide items by reducing margins or increasing their width

I'm having trouble achieving the desired spacing between items, I would like more space between each item but they are currently too close together. I am looking for a margin of 10px or a width of 32% for each item. I have already looked into some re ...

The picture is not adjusting its size within a flexbox arrangement

I attempted to implement the suggestions from this answer, and also referenced this CodePen. However, I am still facing an issue where the image that is supposed to flex maintains its original dimensions unless it is alone on a row when the screen is narro ...

``Is it possible to customize the color of the "buy" button in Opencart according to the stock availability?"

What is the most efficient method to dynamically change button colors in a product listing based on stock availability? I have successfully used JavaScript to check the innerHTML for specific phrases like "out-of-stock" and then changing the button backgr ...

Conflicts arising between smoothState.js and other plugins

After successfully implementing the smoothState.js plugin on my website, I encountered an issue with another simple jQuery plugin. The plugin begins with: $(document).ready() Unfortunately, this plugin does not work unless I refresh the page. I have gone ...

Is it better to have JavaScript and HTML in separate files or combined into a single HTML file?

Do you notice any difference when coding in both HTML and JavaScript within a single .html file compared to separating HTML code in a .html file and JavaScript code in a .js file? Does the functionality remain the same in both scenarios? For example, in t ...

What is the best way to iteratively fade in data from a MySQL database one by one?

How can I load data from a MySQL database and display it one by one with a fade-in effect? Let's say I have a total of 40 images stored in the database. First, I want to display each image like this: <li class="img" style=" list-style: none; flo ...

Obtaining JSON data in a separate JavaScript file using PHP

I have an HTML file with the following content: // target.html <html xmlns="http://www.w3.org/1999/xhtml"> ... <script src="../../Common/js/jquery-ui-1.10.3.js"></script> <script src="../../Common/js/select.js" type="text/javascript"& ...

I have a question about CSS selectors: How can I change the font color of a parent <li> element when the child

After struggling for hours, I'm finally throwing in the towel on this issue. I have an unordered list with no background at the top level and text color of #fff. When rolled over, the background turns #fff and the text color turns #000. The child ul ...

Exploring the Power of Ajax in Struts2

Recently, I started learning about Struts and Ajax. I attempted to create a webpage similar to Gmail, where users enter their username first and then proceed to enter their password. Despite trying out various plugins like Dojo, jQuery, and Jason jars, I ...

Creating an efficient Ajax comment system: A step-by-step guide

I'm looking to experiment with jQuery and Ajax for a bit. My initial idea is to design a simple input box where I can type in my comment and have it appear below without any page reloads. How should I go about achieving this? ...

Expand the dimensions of the bootstrap navigation bar

Is there a way to expand the Bootstrap nav bar to fill the entire screen? Currently, it only occupies half the screen in desktop view, but it is working fine in mobile optimization. <body> <nav class="navbar navbar-expand-lg navbar-light bg-lig ...

Variables for Angular Material themes

My app has multiple theme files, and I select the theme during runtime. .client1-theme{ // @include angular-material-theme($client1-theme); @include all-component-colors($client1-theme); @include theme-color-grabber($client1-theme, $client1-a ...