Utilize JQuery to implement fading effects for clicked elements in a webpage

I've been using a rollover JavaScript plugin to create smooth transitional effects when users hover over clickable page elements. Everything was going well until I decided to switch to making ajax calls instead of page loads for dynamic content. The problem is, I don't fully understand how to modify the plugin because I lack knowledge of JavaScript.

Can someone guide me on implementing a method that will keep an element opaque after it's clicked until another element is clicked?

Below is a snippet from the plugin:


$(document).ready(function(){
    $("#leftBar .divider, #leftBar .dividerLast").fadeTo("9000", 0.8);
        $("#leftBar .divider, #leftBar .dividerLast").hover(function(){
            $(this).fadeTo("5000", 1.0); 
        },function(){
            $(this).fadeTo("5000", 0.8);
        });
});

And here is my code on the front end:


<div class="divider" onclick="$('#employee_form').submit(); SetBackgrounds(); $(this).css('background','url(common/css/images/leftBarBG.gif) top repeat-x');">
     <img src="common/img/employee_image.jpg" class="float"/>
     <h2>Employee Name</h2>
     <h3>Founder &amp; CEO</h3>
     <p>We're passionate about bringing your great ideas to life on the web, and in print.</p>
     <p><a href="mailto:<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea8f87bab67d9bdd7ddc4bbe24b6b0bdbdb899bdb0">@</a>"><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="30555d6e49757364494159685057427176456a676f40">[email protected]</a></a></p>
</div>

I have been making ajax calls using the onclick form submission.

The SetBackgrounds() function that I'm calling onclick needs improvement as I'm still new to JavaScript. It's not as smooth as I'd like, but once we get it working, it should mask sudden background changes. Any constructive criticism is welcome:


function SetBackgrounds() 
{
    $("#leftBar .divider").css('background','url(common/css/images/leftBarBG-hover.gif) top repeat-x');
    $("#leftBar .dividerLast").css('background','url(common/css/images/leftBarBG-hover.gif) top repeat-x');
    $("#leftBar .divider:hover").css('background','url(common/css/images/leftBarBG.gif) top repeat-x');
    $("#leftBar .dividerLast:hover").css('background','url(common/css/images/leftBarBG.gif) top repeat-x');
}

Update: The forms being submitted are hidden forms that submit to a PHP script I wrote that queries a database for employee bios. While there are no issues with the query, understanding this may provide context on what these buttons achieve. The problems I face with this script are purely aesthetic.

Answer №1

It seems like there might be a step missing regarding the opacity change upon clicking the elements.

$("#leftBar .divider, #leftBar .dividerLast").click(function(){
        $(".opaque").fadeTo("5000", 0.8).removeClass("opaque");
        $(this).fadeTo("5000", 1.0).addClass("opaque"); 
});

Next, make the following adjustment:

 $("#leftBar .divider, #leftBar .dividerLast").hover(function(){
        $(this).fadeTo("5000", 1.0); 
    },function(){
    if(!$(this).hasClass("opaque")) $(this).fadeTo("5000", 0.8);
});

If preferred, you can opt for using css() or animate() in place of fadeTo(), or consider shortening the duration time.

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

Remove the footer from the main section

I'm facing an issue with the web page layout of my website. Here is a snippet of the structure: <body> <div class="container"> <div class="sidebar"> </div> <div class="content"> </div> </div> < ...

Utilizing AngularJS to organize JSON data and display it in a table format

I currently have a JSON file that I am extracting data from using Angular.js. However, I would like to format the output in a table as depicted below. Here is my HTML and JavaScript code where I am retrieving the JSON data using Angular: https://i.stack. ...

The IsArray() function in IE8 encounters an issue where it expects an error object

I am interested to know why IE8 is having trouble with this line of code: if (isArray(obj)) When I check in the IE8 javascript console, I see the following: >>obj {...} >>typeof(obj) "object" >>Object.prototype.toString.call(obj) "[obj ...

The compilation process encountered an error: TypeError - Unable to access property 'exclude' as it is undefined (awesome-typescript-loader)

After successfully converting my existing Angular 2 project into Angular 4, I encountered the following error: Module build failed: TypeError: Cannot read property 'exclude' of undefined For more details, please refer to the attached image bel ...

What is the best way to extract a thumbnail image from a video that has been embedded

As I work on embedding a video into a webpage using lightbox, I'm looking for advice on the best design approach. Should the videos be displayed as thumbnails lined up across the page? Would it be better to use a frame from the video as an image that ...

Using Vue.js to update content in input files

I have a Vue.js template file that includes data containing various documents. Within the page, there is a table with rows that feature upload file input buttons, structured like this: <tr v-for="(doc, index) in documents"> <td :id="'doc-& ...

Steps for adjusting the margin of a section using the p tag

Newbie CSS inquiry here... Here's what I currently have in my stylesheet: #topheader { position: absolute; width: 100%; height: 100px; background-color: #D1E6DA; font-size: 200%; } I want to include the following: p { margi ...

Tips on utilizing commas as text input within an HTML input array

Is there a way to pass a comma in an input field to the server using input arrays? The server currently receives comma-separated input values from an array of inputs, which causes it to consider any commas within the input as separators. For example: HTM ...

JavaScript Regex: Removing all characters that are not numbers

There have been several inquiries about this particular question, such as this one on Stack Overflow. Despite my efforts to replicate the solution and research regex, I can't seem to get it to work: $("#button").click(function () { new_number = $ ...

What is the reason for the lack of user data being saved in studio3t?

I'm struggling to identify the issue in my app development process. I'm creating an application that collects user email and password, storing them in a database. The problem lies in the fact that while user passwords are successfully stored, the ...

Transferring image Buffer over API for uploading to IPFS network

My attempt to upload an image to IPFS involves the following steps: I start by uploading the image from my web UI, converting it to a buffer in my Angular component. The next step is to send it via a put/post request (using HttpClient) to my NodeJS Expres ...

Utilizing nested ajax calls

Welcome to my first day and first question on this platform. I hope you can forgive me if my question seems trivial here. My current challenge involves calling ajax within ajax. The first ajax call triggers a controller action that inserts a record into t ...

Top method for utilizing render props in React

Currently, I am employing render model props. However, I have a hunch that there might be an alternative method to achieve the same outcome. Is anyone familiar with another approach? {variable === "nameComponen" && <component/>} {variable === "name ...

Incorrect font displayed on Bootstrap button after inserting hyperlink

This section contains my HTML code snippet: <div class="panel panel-default"> <div class="panel-heading"> Records <button type="button" class="btn btn-xs btn-success pull-right" id="command-add" data-row-id="1"> ...

Changing the direction of the submenu to the left instead of the right

My Bootstrap 4 menu has a submenu that appears to the right of the main menu. However, since the menu is positioned on the far right of the screen, it gets cut off on the right side. I'm looking for a way to make the submenu appear on the left side o ...

What is the best way to display a mySQL database in an HTML div table?

Showcasing the grades in a table format: username assignment weight mark a a1 10% 50% b a1 10% 60% Can this be achieved using PHP/HTML? <div class="a"> <div class="divTabl ...

Inquiry about form submission

I currently have a form on one domain (domain 1) that is being submitted to another domain (domain 2) using PHP cURL functions. However, the need to also send certain data to yet another domain (domain 3) has left me feeling perplexed. My initial idea was ...

Trouble retrieving data (React-redux)

Greetings! I am currently working on a project involving the Spotify API and attempting to retrieve new releases. While the data is successfully passed down to the reducer, I encounter an issue when calling the fetch action in my App component. When I try ...

Find similarities and differences between two CSV files

Dealing with 2 large files, both exceeding 1 million rows: The first file contains only an md5 hash The second file contains pairs of md5 and email addresses My task is to compare these two files and if the md5 hashes match, write the corresponding emai ...

What is the method for defining a CSS property for the ::before pseudo element within an Angular component?

Can TypeScript variables be accessed in SCSS code within an Angular component? I am looking to achieve the following: <style type="text/css"> .source-status-{{ event.status.id }}::before { border-left: 20px solid {{ event.status.colo ...