How to fix a sticky Jquery Image Hover issue

Having some trouble creating jQuery hover effects for images. My code doesn't seem to be working as expected and I'm not getting any output. Here's the code I have so far, hoping someone can lend a hand...

gallery.html

<html>
 <head>
 <title>Test</title>
 <link rel="stylesheet" href="style.css" />
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
 <script src="js/default.js"></script>
 </head>
 <body>
 <div class="gallery">
 <ul class="items">
  <ul>
     <li><span class="img_frame"><a href="img/s6300159.jpg"><img src="img/test1.jpg" /></a></span><div class="img_desc"><span>22</span></div></li>
     <li><span class="img_frame"><a href="img/s6300159.jpg"><img src="img/test1.jpg" /></a></span><div class="img_desc"><span>23</span></div></li>
     <li><span class="img_frame"><a href="img/s6300159.jpg"><img src="img/test1.jpg" /></a></span><div class="img_desc"><span>24</span></div></li>
  </ul>
 </ul>
 </div>
</body>
</html>

style.css

.gallery {overflow:hidden; width:1000px;}
.gallery .items { margin-bottom:50px; height:320px; }
.gallery .items li { position:relative; float:left;  width:290px; height:180px; margin-right:38px; margin-bottom: 30px; }
 .gallery .items li img { width:277px; height:165px; }

 .img_desc {
position: absolute;
    display: block;
    top: 10px; 
text-shadow: 1px 1px 0 #ffffff;
color: #262626;  
background: url(img/benefits_on.png) repeat;
width: 36px;
right: 5px;
text-align: center;
    }


    .img_frame {
    margin-top:3px;
     padding:1px;
     display:inline-block;
     line-height:0px;
     background:#fff;
     border:1px solid #ccc;
      }

    .img_frame img {
     padding:1px;
     border:4px solid #f2f1f0;
    }
    .img_frame a { display:block; }

    .hover_image { background:url("img/preview_image.png") center center no-repeat; }

default.js

<!-- Image hover effect -->
function image_hover(frame){
var link_content = jQuery(frame).find('a[href^=http], a[href*=www], a[href=#], a[href$=html], a[href$=php], a[href$=asp], a[href$=htm], a[href$=shtml], a[href$=aspx]');
var image_content = jQuery(frame).find('a[href$=jpg], a[href$=png], a[href$=gif], a[href$=jpeg]');
var video_content = jQuery(frame).find('a[href*=vimeo], a[href*=youtube], a[href*=swf], a[href*=flv], a[href*=avi], a[href*=mov], a[href*=mpg]');

link_content.addClass("hover_link");
image_content.removeClass("hover_link").addClass("hover_image");
video_content.removeClass("hover_link").addClass("hover_video");

jQuery(frame).find("a > img").hover(
    function() {
        if(!jQuery(this).parent().hasClass("no_hover")){
            jQuery(this).stop().animate({"opacity": ".6"}, "400");
        }
    },
    function() {
        jQuery(this).stop().animate({"opacity": "1"}, "400");
});

jQuery(frame).children("a.no_hover").removeClass("hover_image");
return false;
}

jQuery(function(){

image_hover('.img_frame');
 });

........................

Answer №1

Are you looking to create a hover effect on your website? I personally like the glowing border effect with a decrease in opacity and a background lift. If this is the effect you're going for, it's possible that there was an error in specifying the image location within your .hover_image class. Try adding a background color to the class like this:

.hover_image { background:#00ff00 url("img/hover_image.png") center center no-repeat; }

By making this adjustment, you should see the same effect that I experienced.

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

Bring in JS into Vue from the node_modules directory

Apologies for my limited knowledge in this area, but I am currently working on integrating and importing This Grid System into my Vue project. However, I am facing some challenges. Typically, I import plugins like this: import VuePlugin from 'vue-plu ...

Adding information to a table row using pagination in CakePHP

I am currently working on a basic data view with an HTML table. One question that I have is how to add the next set of data below the last row when clicking on the pagination link. ...

Ignoring tags inside a regular expression can be achieved by using the appropriate

Our project utilizes a RegExp to showcase the titles of cards received from the deck. Lately, we have noticed that the deck sometimes sends titles in different formats which are not displaying properly. Previously, the string format was: const res = `&l ...

Received an error stating "database.ref is not a function when working with vue 3."

I've been searching extensively, but I can't seem to make Firebase Realtime Database work for my web app. The goal is to manage products by adding, editing, viewing, and deleting them from a list. Below is the current code snippet from data.js. A ...

A guide on extracting the values of checked checkboxes by their ID using javascript

I'm currently attempting to extract the values of selected checkboxes. These checkboxes have distinct IDs because they are specified within a modal window. <input type = 'checkbox' id = 'audience_Name-$row[asset_ID]' value = &a ...

Callback functions can be executed before and after an event occurs

I have been utilizing the fantastic tablesorter plugin for my project. I am looking for a way to perform additional actions both before and after the sort click event is executed. Is there a method to incorporate before and after callback functions into a ...

Warning: Electron alert - Function _crypto.default.randomFillSync unavailable

I am trying to implement notifications in my Electron project on a Node server. To do this, I have installed the node-notifier module in my app folder using the following command: $ npm install --save node-notifier After installation, I added a button t ...

Implement VueJS functionality to prevent form submission upon submission and instead submit the form upon keyup

My form has the following structure: <form id="myForm" action="/searchuser" method="POST" @submit.prevent="onSubmit(inputValue)"> <div class="field"> <label class="label">Name</label> <div class="control"> ...

Steps to open a webpage with a URL that includes #tags=green, pink, and white at the conclusion

Here's the challenge - Open your page with a URL that includes #tags=green,pink,white at the end Create a JavaScript script that extracts the tags from the URL and displays them in a list, with each tag as a separate list item. For instance, if the ...

Troubleshooting the onSubmit function issue within a react-bootstrap navigation dropdown

I've hit a roadblock trying to troubleshoot this issue with my first react project. The goal is to integrate a search input within a navigation dropdown using react-bootstrap. I believe I'm making progress as it works fine when the form is outsid ...

Exploring the Benefits of Utilizing External APIs in Next JS 13 Server-side Operations

Can someone provide more detail to explain data revalidation in Next JS 13? Please refer to this question on Stack Overflow. I am currently utilizing the new directory features for data fetching in Next JS 13. According to the documentation, it is recomme ...

Embark on a journey through Express.js routes with a unique context

After grappling with this issue for a few days, my brain feels fried and I can't seem to find the most efficient solution. My ultimate goal is to be able to repeat a route journey with new context data at the start. For example: app.get('/test& ...

adding a new transformation to the current properties

Is it possible to add a new transform property to existing ones? For instance, let's say I have a div.animation with the following style: .animation { transform: translateX(-50%) translateY(-50%); } Now I want to include transform: scale(1) to ...

Mobile navbar fails to collapse upon clicking links

I'm attempting to have my code collapse when the links are clicked, but I'm running into some issues. I attempted adding data-toggle to the link, however in doing so, the links stopped functioning. <HTML> <nav class="navbar navbar-expa ...

Does CSS Horizontal Padding Percentage Stop Relative to Element Once Maximum Width is Reached?

I'm currently in the process of developing my latest portfolio website at and I'm facing a perplexing padding dilemma that has left me stumped. The approach I'm taking with the layout involves each row of content consisting of both an outer ...

Differentiate between minimum and maximum values on ion-range sliders with discrete color options

I am currently working on customizing the theme of my ionic app, specifically trying to assign different colors to the min and max knobs on an ion-range component. At the moment, I am only able to apply a single HTML property called "color" to the selector ...

Changes made to the CSS are not being reflected on the live production server hosted on our Bitbucket repository

My WordPress website is hosted on a Linux server and connected to a Bitbucket repository, but I am experiencing an issue where CSS changes are not reflecting on the live site. I have made changes to the HTML code and style sheet, and while the HTML code u ...

How to incorporate diagonal lines in CSS within its parent container?

Is there a way to create a diagonal line that fills in and fits perfectly into a box using just CSS, without the need for any background images? div.diagonal-container { border: 1px solid #000; width:400px; height:400px; margin: 0 auto; ...

The hyperlink tag doesn't respond to clicks in Safari, yet functions properly in all other web browsers

I'm encountering an issue with my header drop-down menu in Safari—it works perfectly in Chrome, but when I try to open the drop-down menu in Safari, it's unresponsive. Clicking on it does nothing, preventing me from accessing other drop-downs. ...

Leveraging jQuery's `.eq()` method on multiple class selectors

Is there a way to effectively utilize the 'eq' function on multiple classes? Due to the non-sequential nature of the divs with class 'a', I am encountering difficulties with using the 'eq' function to update their class. Inter ...