Show one image at a time when hovering over the play button

Hi, I'm struggling to figure out how to make the play button appear only on a specific image when hovering over it. Currently, I have multiple images with different effects and have used JavaScript to show the play button when hovering over one of them. However, the issue is that when I hover over one image, the play icon shows up on all images simultaneously.

Is there a simpler way to achieve this where the play icon will only display when hovering over the particular image?

Javascript:

$(".portbg1").hover( function () {
$(this).addClass("active");
$(".playbutton").addClass("active");
}, function (){
$(this).removeClass("active");
$(".playbutton").removeClass("active");
});

HTML:

<div class="port_item"><div class="playbutton"></div><div 
class="portbg1"><div class="port_item_title" data-modal="#modalOne"> . 
<h4>Showreel</h4></div></div></div>

Other similar classes include portbg2, portbg3, portbg4, etc., up to portbg9.

CSS:

.playbutton {
   position: absolute;
   background-image: url(IMAGES/openicon.png);
   background-size: 80px 80px;
   background-repeat: no-repeat;
   background-position: center center;
   width: 80px;
   height: 80px;
   left: 50%;
   margin-left: auto;
   margin-right: auto;
   top: 50%;
   transform: translate(-50%,-50%);
   z-index: 1;
   opacity: 0;
   overflow: hidden;
   transition: all 0.2s;
}

.playbutton:hover {
   opacity: 1;
}

.active {
   opacity: 1;
}

Answer №1

Simply executing:

$(this).siblings('.playbutton').addClass("active");

Executing the same action for removing a class.

Therefore, the end result would be:

$(this).addClass("active").siblings('.playbutton').addClass("active");

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

Is there a way for me to directly download the PDF from the API using Angular?

I'm trying to download a PDF from an API using Angular. Here's the service I've created to make the API call: getPDF(id:any) { return this.http.get( `url?=${id}`, { responseType: 'blob' as 'json', obs ...

Tips for setting the tabindex on an element that has an opacity of 0

I have created a drag and drop image upload field with a hidden input element to style the upload button according to the design. However, I am concerned about accessibility and want the upload functionality to trigger when the user presses 'Enter&apo ...

AngularJS - Preventing hyperlink functionality on specific elements within ng-repeat loops

I am currently working on a project where I need to display a list of events using ng-repeat. Each event should be clickable and direct users to another location, which is functioning correctly. However, the issue arises when the ng-href attribute is also ...

Display the total combined hours of all events for each day in FullCalendar

Currently, I am utilizing the FullCalendar plugin created by Adam Shaw in conjunction with knockoutjs. With this setup, I have successfully implemented functionality to add, delete, and drag-and-drop events. However, in both week mode and day mode, I am ai ...

AngularJS requires that JSON object property values be converted to strings in order to be displayed as actual templates

Each tab click accesses a json array containing unique templates such as ui-grid or c3 chart directive (c3.js). When a specific tab is clicked, the template in string format must be rendered into actual templates like ui-grid, c3-chart, etc. var sampleJs ...

Removing the ajax scroll and ajax loader functionality in my jQuery script

I have implemented an ajax loader in the code snippet below. The issue arises when the data fetched from the database is fully displayed, the scroll function continues to run infinitely and the ajax loader image remains visible. I am looking for a way to ...

The functionality of @Output and custom events appears to be malfunctioning

I am a beginner in Angular and attempting to pass data between child and parent components. In the child component.ts file: @Output() doubleClick = new EventEmitter<string>(); onDoubleClick(nameAccount: string){ this.doubleClick.emit(nameAccoun ...

The i18n feature in node.js seems to be malfunctioning as the setLocale function is not working properly. Regardless

Something seems off with my usage of the i18n library, but I believe I'm following the correct steps. I've been attempting to switch the locale. Here's my current code. Despite calling setLocale on the global i81n variable, it continues to ...

JavaScript struggles to obtain the timezone information when Daylight Saving Time is

Can someone help me with setting a user's timezone offset for PHP through ajax? When a page is loaded with session data, if there is no pre-existing data, the following script is inserted into the page: <script type="text/javascript"> $(doc ...

Establish breakpoints for columns in Bootstrap 4

I have been working on creating a grid layout using rows and columns, but I am struggling with setting up responsive breakpoints using Bootstrap. Specifically, I want the layout to display three columns on desktop screens, but collapse into a single column ...

Displaying burger options when hovering over the menu

How can I prevent my menu from collapsing when hovering over (.menu)? $('.menuBurger').hover(function() { $('.menu').slideToggle(300); }); .menu { width: 70px; height: 60px; background: #ccc; display: none; } <script src="https: ...

Correct the positioning upon refreshing within a table containing multiple pages

Struggling with my code in index.php as it maintains the position inside the table but loses track of the web page number. The refresh is triggered by a button that updates a value in the selected row (in column B) by running a php script validation.php. I ...

conflicting character encoding systems

Request normally comes in this format: Parameters: {"utf8"=>"✓", "status_id"=>"12686"} However, from one particular client, the request looks like this: Parameters: {"utf8"=>"\xE2??", "status_id"=>"12686"} As a result, I am encounter ...

What is the best method for rendering or retrieving "field[]" in Django forms?

Are you using an array field in Django to dynamically add fields with JavaScript? For example, when a user clicks on a button, a new field appears. However, you're having trouble getting Django to render the field as "field[]" name and retrieving tha ...

Troubleshooting an Angular.js "Hello World" application that is malfunctioning

I've been trying to get a simple Hello World app working by following different tutorials, but it doesn't seem to be functioning correctly. I've double-checked my code and everything looks right to me. Could someone please assist me in troub ...

Is it possible to execute a script from a different directory?

Currently, I am developing a nodejs package that involves executing a bash script within the program. The specific bash script, "./helpers/script.sh", needs to be run using a relative path. This means that when users install and run the package, the script ...

I am encountering an issue where my Vue navbar is successfully changing the route but not updating the corresponding router-view

I have been working on a single-page application using Vue and I encountered an issue with the navbar when navigating through routes. The problem is that after the first click on a navbar item, the route changes successfully but the router-view does not up ...

Is the latest Swiper JS version compatible with outdated web browsers?

Seeking information on browser compatibility. I am interested in upgrading to the latest version 8.4.5 of Swiper JS for my project, currently using version 4.1.6. Upon examining their shared Github repository file .browserslistrc, I noticed changes that ta ...

Implementing gridlines on a webpage using HTML and JavaScript to mimic the grid layout found in Visual Studios

Currently, I have a grid snap function in place, however, I am looking to add light grey lines horizontally and vertically on my Designing application. The goal is to achieve a similar aesthetic to Visual Studios' form designing feature. Utilizing so ...

Error: implode() function received invalid arguments

I have a form that sends data from one page to another using jQuery. Here is an example of how it works: <?php $counter = 0; $sqlmasmohType = mysql_query("select * from masmoh"); while ($rowmasmohType = mysql_fetch_array($sqlmasmohType ...