Flickering problems occur when using Jquery to load MVC Views upon hovering

I am trying to create a hover effect that expands and changes the content of each div when hovered over, and reverts back to its original state on mouseout. To achieve this, I am using MVC partial views:

(Subpages.cshtml)

<div id="subpages" class="mx-auto d-flex justify-content-evenly">
    <div class="subpage" id="subpage1">
        @Html.Partial("Subpage1Narrow")
    </div>
    <div class="subpage" id="subpage2">
        @Html.Partial("Subpage2Narrow")
    </div>
    <div class="subpage" id="subpage3">
        @Html.Partial("Subpage3Narrow")
    </div>
</div>

(Subpage1Narrow.cshtml)

<div class="d-flex align-items-start flex-column" style="width: 456px;">
    <p class="subpage__title mb-4 mx-4"><b>Subpage<br>1</b></p>
    <br>
    <p class="mx-4">...</p>
    <button type="button" class="btn btn-danger mt-auto mb-5 mx-4" id="subpage1__button" style="font-family: var(--alt-font)"><b>Learn more <span class="bi bi-arrow-right"></span></b></button>
</div>

(Subpage1Wide.cshtml)

<div class="d-flex flex-column align-items-center mx-auto" style="width: 1368px; height: 681px;">
    <p class="text-center subpage__title mb-4 mx-4 mt-auto"><b>Subpage 1</b></p>
    <br>
    <b class="text-center mb-5 subpage__text--extended">...</b>
    <div class="row w-50 text-center mb-3">
        <div class="col">
            <img src="~/img/ICON1.svg" width="57" height="49">
        </div>
        <div class="col">
            <img src="~/img/ICON2.svg" width="66" height="59">
        </div>
        <div class="col">
            <img src="~/img/ICON3.svg" width="37" height="56">
        </div>
    </div>
    <div class="row w-50 text-center mb-5">
        <div class="col">
            <b class="d-block subpage__subtitle--extended">1</b>
        </div>
        <div class="col">
            <b class="d-block subpage__subtitle--extended">2</b>
        </div>
        <div class="col">
            <b class="d-block subpage__subtitle--extended">3</b>
        </div>
    </div>
    <button type="button" class="btn btn-danger mt-4 mb-5" id="subpage1__button" style="font-family: var(--alt-font)"><b>Learn more <span class="bi bi-arrow-right"></span></b></button>
</div>

(site.css weird hack but I had issues with other approaches)

#subpages:hover > .subpage:not(:hover) {
    width: 0;
}

(HomeController.cs)

public IActionResult GetView(string viewName)
{
    return PartialView(viewName);
}

(site.js)

function capitalize(str) {
    return str.charAt(0).toUpperCase() + str.slice(1);
}

$(document).ready(function () {
    $(".subpage").mouseover(function () {
         $(this).load("/Home/GetView", {viewName: `${capitalize($(this).attr('id'))}Wide`})
    });

    $(".subpage").mouseout(function () {
         $(this).load("/Home/GetView", {viewName: `${capitalize($(this).attr('id'))}Narrow`})
    });
});

However, I am experiencing some issues with the reliability of this method. The content of the divs flickers when I move my mouse, and sometimes does not revert back on mouseout. As this is my first time combining C# with front-end development, I suspect I may be making a mistake. Is there a solution to this issue, or should I consider a different approach entirely?

Thank you for your assistance.

Answer №1

What do you think of including mousemove functionality?

$(".subpage").mousemove(function(){
  $(this).load("/Home/GetView", {viewName: `${capitalize($(this).attr('id'))}Wide`})
});

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

Error message: Iframe chrome encountered a Uncaught DOMException when attempting to access the 'localStorage' property from 'Window': Document does not have permission

I recently developed a JavaScript widget that utilizes localstorage to set and retrieve properties of the window. Upon opening this widget in Chrome, I encountered an error message: Uncaught DOMException: Failed to read the 'localStorage' prop ...

Bony Scaffold - halting the motion of specific components

Currently, I am utilizing skeleton to create a fluid layout, which is functioning effectively for the most part. However, I have encountered an issue specifically with the 2 column layout on Magento at this URL: In this setup, the navigation on the left s ...

Pull data from another domain's DIV using jQuery's load/ajax function

I need to load content from a different domain into a DIV on my JSP page. For example: $("#myDiv").load("https://www.google.com") The issue I'm facing is that the request is being blocked by the browser's same origin policy. I've explore ...

I'm struggling to make the jquery parentsUntil function work properly

Would appreciate some help with using the jquery parentsUntil method to hide a button until a radio box is selected. I've been struggling with this for a few days now and can't seem to figure out what I'm doing wrong. Any insights would be g ...

Trigger a call to action within a partial view to execute again

This question has been discussed numerous times on SO, but I'm still struggling to make it work. None of the proposed solutions are fixing the issue for me. Here's the scenario: I have a main form where the user inputs data and uploads a picture ...

jQuery mobile : accessibility helper for hidden elements

Within my HTML structure: <div data-role="fieldcontain" id="containdiv" class="no-field-separator"> <label for="field1" class="ui-hidden-accessible">To</label> <input type="search" name="field1" id="field1" autocorrect="off" a ...

What are the steps to turn off the mobile version of a website?

My website is currently not fully responsive for mobile devices. I am wondering if there is a way to ensure that my app always loads the desktop version when accessed from a mobile device. The site was developed using Java, Bootstrap, HTML, CSS, JavaScri ...

Using the Slim framework to communicate through JSON

When attempting a simple POST request, I am having trouble reading the JSON data no matter what I try. $.ajax({ url: 'server/account/session', type: 'POST', data: { "username": name, "password": password} , ...

Learn how to use CSS flexbox to easily vertically center items within a container with a full-height background

I'm having trouble with aligning text vertically centered within a box and making sure the background color stretches to full height. HTML: <div class="feature-content"> <div class="feature-visual"> <div class="embed-container"> ...

Obtain the date value in the format of month/day/year

How can I retrieve the date from 2 months ago and format it as MM/DD/YYYY? I tried this code snippet, but it's returning a value in the format "Tue Feb 11 14:30:42 EST 2014". var currentDate = new Date(); currentDate.setMonth(currentDate.getMonth() ...

Having trouble importing font-face in scss

Currently, I am working on incorporating a Google font into my project. This is the desired outcome: https://i.sstatic.net/jIO7q.png However, the actual result is different: https://i.sstatic.net/V2KhW.png The code snippet in App.vue looks like this ...

When using JQuery, the $.each method may not properly iterate through JSON data

I am working on a project where I need to dynamically create HTML checkboxes based on the 'colour' data retrieved from a database in JSON format. My initial approach involves making an AJAX request to a controller: $.ajax({ url: "Home ...

Storing the order of jQuery UI Sortable in the WordPress Admin Panel

My goal is to customize the order of taxonomy terms for each individual post in Wordpress. I have created a metabox on the EDIT POST page that contains custom taxonomy terms and made them sortable using JQuery. Here is my setup on the Wordpress backend: ...

Restore to the prior iteration of jQuery

Encountered an issue after installing two libraries, one updating to jQuery 1.9.1 and the other installing 1.9.2. Found both versions of jQuery in my Scripts folder, so attempted an upgrade-package in nuGet to version 2.0.1. My project still requires com ...

Hide or show list items in an unordered list using jQuery

I am interested in creating a script that can toggle between "show more" and "show less" functionality for elements in a list. I came across this script: HTML <ul id="myList"> <li>One</li> <li>Two</li> <li> ...

Arranging CSS text in a parallel format and aligning it vertically

I am working on a layout with two columns of text placed side by side, where one column is right aligned and the other is left aligned. Below is my current code: .alignleft { float: left; } .alignright { float: right; } .list-unstyled { padding ...

Effect on Label in WordPress Contact Form 7 When Input Field is Populated

Currently, I am attempting to achieve the floating label effect on Contact Form 7 and have encountered an issue. Although I have successfully implemented the label effect on input:focus, I am struggling to make it persist once text has been entered and foc ...

How can I align two tags horizontally using HTML and CSS?

I've been diving into HTML and CSS lately and making some progress, but I've hit a snag. I'm trying to create a horizontal ul list with li elements on the same line at the top of the screen, similar to Stack Overflow's layout. Although ...

How can I incorporate a personalized SVG path to serve as a cursor on a webpage?

Is there a way to enhance the functionality of binding the 'mousemove' event to a div and moving it around the page while hiding the real cursor? Specifically, can we change the shape of the circle to an SVG path and drag the SVG path around the ...

Deactivate the first item in a jQuery sortable list

I'm working on a sortable list and I want to prevent the first item from being moved, so that the input field stays in place. Check out my list below: <ul id="sortable" class="connectedSortable"> <input name="name1" class="inputfield" t ...