What could be causing the .hover function to malfunction and how can I make it so that the .hover function only applies within the corner radius area?

I am attempting to make circles react to my jquery .hover function. Below is the JavaScript code I am using:

jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", Math.max(0, (($(window).height() - this.outerHeight()) / 2) + 
                                            $(window).scrollTop()) + "px");
this.css("left", Math.max(0, (($(window).width() - this.outerWidth()) / 2) + 
                                            $(window).scrollLeft()) + "px");
return this;
};


$(document).ready(function()
{
    $('#logo').center();
    j=8;
    size=200;
    $.each($(".circle"), function() {
        $(this).css('z-index', j);
        $(this).css({
            height: size+"px",
            width: size+"px",
            borderRadius: size+"px",
            });
        size = size+50;
        $(this).center();
        j--;
    });

});

  $(".circle").hover(
    function() {
      $(this).animate({
        height: '+=25px',
        width: '+=25px',
        top: '-=12.5px',
        left: '-=12.5px'
        }, 'fast'
      );
    },
    function() {
      $(this).animate({
        height: '-=25px',
        width: '-=25px',
        top: '+=12.5px',
        left: '+=12.5px'
        }, 'fast'
      );
    }
  );

This is how my body HTML is structured:

    <div id='logo'><img src='_Source/Logo.png' alt='RB'/></div>
<div id='a1' class='circle'></div><div id='g1' class='circle'></div>
<div id='a2' class='circle'></div><div id='g2' class='circle'></div>
<div id='a3' class='circle'></div><div id='g3' class='circle'></div>
<div id='a4' class='circle'></div><div id='g4' class='circle'></div>

The functionality works on jsfiddle, here

However, it fails to work on my website, here

If I still had hair, this issue would have me pulling it out.

Thank you.

Answer №1

You have the .hover() binding call placed outside of the .ready() binding, in the <head> section. As a result, you are trying to bind the .hover callback before the DOM is fully loaded. To fix this issue, simply move it inside your .ready() function.

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

Utilizing Angular's $locationProvider in conjunction with ASP.NET MVC routing

Currently, I am managing routing in ASP.NET MVC using the RouteCollection class. However, my front end is built with Angular and there are instances where I need to update the URL using Angular's $location service while also supporting HTML5. To achie ...

Ensure the table body scrolls the full height of the page while maintaining a fixed header when the table is out of view

My goal is to implement scroll bars for overflowed content within a single table on the page. Despite reading numerous posts on this topic and experimenting with various methods like setting height to 100% or using flex layout, I still can't seem to a ...

Unusual behavior of .replace() function observed in Chrome browser

<div> <input type="text" class="allownumericwithdecimal"/>saadad </div> $(".allownumericwithdecimal").live("keypress keyup ", function (event) { $(this).val($(this).val().replace(/[^0-9\.]/g, '')); var text = ...

Utilizing jQuery to scrape HTML and dynamically manipulate elements

Is there a way to retrieve HTML content from a different subdomain and incorporate it into the current site? HTML snippet: <head> <body> <div id = "items"> <div id = "#one"> <ul> <li><a href = "#">C ...

The Border Radius Problem in Google Chrome

Greetings! I am currently working on a project for a website and have encountered an issue with the gallery on the projects page. The images are meant to be displayed as circles, and when hovered over, they should maintain their circular shape and have a b ...

The problem with the Next.js 14 generateStaticParamsparams parameter is that it is currently

I'm using this documentation as a reference to extract parameters from the URL in my generateStaticParams function: https://nextjs.org/docs/app/api-reference/functions/generate-static-params#generate-params-from-the-bottom-up This is the route I am w ...

The Vue.js transition feature seems to be malfunctioning when trying to display a modal

I can't figure out why my animation isn't working with Vue transitions. Here is the code I have: <template> <teleport to="body"> <div class="modal-overlay" v-if="loading"> <transitio ...

It seems that the maximum call stack size has been exceeded, resulting in a

Within this dropdown, I have incorporated a checkbox containing values in the form of an object. (refer to attached image) Every time I make a selection from the dropdown, there is a watch function that updates this new value, which is essentially an arra ...

Troubleshooting issue with rendering <li></> using array.map: Map's return statement is producing undefined output

Trying to implement pagination in a React project and facing issues with rendering a set of li elements within an ul. The renderPageNumbers function is returning undefined in the console, even though I can see the array being passed and logging out each el ...

Making an Ajax request to a RESTful web service from a different domain

Similar Question: Exploring methods to work around the same-origin policy I need to communicate with a RESTful web service from a different IP address using an AJAX request on my HTML page. Unfortunately, AJAX does not support cross-domain requests. ...

How can I invalidate the Authorization header in a request?

After delving into the Basic Authentication algorithm and successfully implementing it, I've encountered an issue. The Authorization header in the request seems to never expire, allowing the client to continuously access protected content without re-a ...

Understanding the Typescript Type for a JSON Schema Object

When working with JSON-schema objects in typescript, is there a specific type that should be associated with them? I currently have a method within my class that validates whether its members adhere to the dynamic json schema schema. This is how I am doing ...

Adjust the Scope in Angular-Charts.js Post-Rendering

I am currently facing a challenge with displaying multiple charts using the angular-charts.js framework. The issue is that I require all the charts to have the same scale, but each chart currently has its own scale based on the displayed data. Unfortunatel ...

Encountered issue while jasmine mocking angular $http - Error: describe function does not support a done parameter

I am currently working with an angular factory that looks like this: .factory('widgetFactory', ['$http', function($http){ function getWidgets(){ return $http.get('http://example.com/api/widgets/') .then(function(re ...

Incorporating Sass into an HTML document

Recently, I discovered Sass and went through its documentation. I successfully installed the package on my Ubuntu system alongside Ruby and Haml. Now I'm eager to learn how to use it with Wordpress or a basic HTML file. Being new to this, I'm see ...

Exploring the versatility of orderBy and filter in handling cross-referenced content across multiple JSON objects

Is there a way to filter and search for the item name when the item details are sourced from another JSON object? Demo: http://codepen.io/anon/pen/GjAxKX While the rest of the filtering and ordering functionalities are functioning correctly, I am struggl ...

Tips for setting a dynamic value to a parameter in an MVC ActionLink with the help of Jquery

I am working on an Index page that displays records in a table. For each record, there is a DropDownList included. What I aim to achieve is when a record is selected using the ActionLink on the side, not only the ID of the record is sent but also the ID o ...

Difficulty in toggling on and off several form elements with JavaScript

Trying to control multiple form elements on an HTML page with JavaScript has presented a challenge for me. In my form, each row contains a checkbox that should enable/disable the elements on that row. The issue I'm facing is that only the first two f ...

How PHP Processes Fragment Identifiers within URLs

Looking for some advice from the community on a tricky situation I'm facing. Here's the issue at hand: I have developed a website with dynamic content pulled via AJAX and displayed using JS. To allow direct links to my content, I modify the frag ...

Enhance your calendar with sleek jQuery styling

Currently, I am utilizing the jQuery-ui.css (smoothness) solely for the calendar CSS. Can anyone provide me with a comprehensive list of all the calendar CSS functions available in it? I'm looking to avoid using any unnecessary CSS that might be causi ...