relocating the title of a tooltip

Could someone please assist me with adjusting the position of the caption above the image in the provided jsfiddle? Currently, the caption is displaying below the image and I am unable to figure out how to move it. Any help would be greatly appreciated.

Sample Code

<script type="text/javascript">
$(function(){
  $("ul.thumb li").hover(function() {
  $(this)
    .css('z-index', '10')
    .find('img').addClass("hover")
    .stop()
    .animate({
       marginTop: '-150px',
       marginLeft: '-150px',
       top: '50%',
       left: '50%',
       width: '300px',
       height: '300px',
       padding: '20px'

     }, 200, function() {

        var $this = $(this),
        h = $this.height();
        $caption = $('<div class="caption">' + this.title  + '</div>')
            .css('top', h.toString() + 'px');
            $this.after($caption);

      }); 

   }, function() {

 $('.caption').remove();
 $(this)
.css('z-index', '0')
.find('img').removeClass("hover")
.stop()
.animate({

    marginTop: '0',
    marginLeft: '0',
    top: '0',
    left: '0',
    width: '200px',
    height: '200px',
    padding: '5px'

 }, 400);
});
});
</script>

I appreciate any assistance you can provide.

Answer №1

Take a look at the updated FIDDLE for reference.

The crucial line to focus on is:

.css('top', -h.toString() + 'px');

This code snippet is responsible for positioning the div relative to the text. By adding a negative symbol before h.toString(), you can adjust the position above the image. For more precise adjustments, consider multiplying h.toString() by a coefficient like -.8 or -.92. Keep in mind that adjusting the position above the image may require fine-tuning based on the height of the text div.

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

When I close all of my tabs or the browser, I aim to clear the local storage

Could you recommend any strategies for clearing local storage upon closing the last tab or browser? I have attempted to use local storage and session storage to keep track of open and closed sessions in an array stored in local storage. However, this meth ...

In order to retrieve the latitude and longitude of a specific address using arcGis JavaScript, follow these

Hello, I'm wondering how to obtain the Latitude and Longitude using arcgis JavaScript. Can anyone help me with this? ...

The issue with the floating of the Div element on the right side appears to be tied to the current CSS present in the code

Struggling to create a clean header using HTML and CSS, I'm facing an issue where my button list refuses to float to the right, resulting in an awkward layout. I attempted various methods like floating the list, floating the ul, and even floating the ...

Viewing the XML response generated by a JavaScript file (SOAP Request) on the IIS server

My current setup involves utilizing a calendar system with an API accessible via SOAP requests on an IIS server. Initially, my approach was to create an HTML page and use JavaScript to display the SOAP request response. However, the response did not retur ...

The React-Native app freezes on the splash screen when running on iOS, while it functions perfectly on Android

My React-Native 0.62.3 app is not working on iOS. It launches, receives the bundle from metro, and then just displays the splash screen without any further action. Here's the run log: flipper: FlipperClient::addPlugin Inspector flipper: FlipperClient: ...

Unexpected padding seen on iPad while browsing with Safari

During my testing of a website at the link: This Website I encountered an issue when viewing the site on an iPad using Safari. While everything appeared normal in browsers like IE, Chrome, and Firefox on my computer, I noticed a strange margin at the righ ...

Transitioning smoothly from one specific location to another through a scrolling motion

Imagine having a box that is currently off from its correct position due to tranform:translateX(-200px) https://i.sstatic.net/2Mgwm.jpg Just below the picture, there are two <section>'s displayed - one as a large grey box and the other as a whi ...

whole <li> tag with both <a href> and <span> elements to create a clickable link

[RESOLVED] Solution found: I finally realized that the closing </a> tag comes before the <span> tags in the initial HTML code provided in the question, which was causing the issue! Thank you to everyone for your assistance!! This just goes to s ...

ng-show directive in AngularJS is not functioning properly when utilized with CLI

After setting up my Angular app with ng new app, I attempted to hide certain elements conditionally using ng-show. Unfortunately, it doesn't seem to be working as expected. <span ng-show="false">Angular App</span> Regardless ...

Unable to scroll within a div while utilizing Tailwind CSS framework

Setting up this middle div on a page presents the following situation: The Top Bar should remain sticky and stationary The Middle section should scroll as new content is added or if the user scrolls up or down The Bottom Bar sh ...

What is the solution to the error "Maximum update depth exceeded. Calls to setState inside componentWillUpdate or componentDidUpdate" in React?

Everything was running smoothly until this unexpected issue appeared. I attempted to change the condition to componentDidMount, but unfortunately, that didn't resolve the problem. The error is occurring in this particular function. componentDidUpd ...

Update the styling in Typescript once the item has finished loading

Imagine you have a scenario where there's a list and an array populated with data. <ul class="list-group"> <div *ngFor="let data of exampleArray"> <li id="createId(...)" class="list-group-item"> <div cla ...

Obtain the texture from a user upload and apply it to a geometry in three.js

As a beginner in three.js and JavaScript, I am excited about the possibilities and have been creating small Three.js scenes to improve my skills. My ultimate goal is to build a 3D website, but I am currently stuck on how to allow users to upload an image f ...

The livereload.js file refuses to load in the browser, causing gulp to crash in a Windows Node.js project

Recently, I utilized npm-windows-upgrade to update my npm to the latest version in order to resolve an issue where node modules were exceeding the windows maximum path length due to nested dependencies. Following this update, livereload.js stopped loading ...

What is the process for retrieving a value from JSON utilizing JavaScript?

Unfortunately, I am completely stumped when it comes to Javascript. I'm attempting a few solutions based on online resources. If anyone could offer some assistance, that would be greatly appreciated. Below is the JSON data provided. It has been conde ...

several parameters for the `ts-node -r` options

Can I include multiple require statements in the package.json script before running with ts-node -r? "scripts": { "start": "ts-node -r dotenv/config newrelic src/index.ts", } I'm having trouble adding both "dotenv/config" and "newrelic" si ...

The intricate dance between JAVA and HTML

Can Java be compatible with HTML and JS? Is it possible for them to cooperate without using JSP? In order to connect the WEKA function, we utilized Java code through a JAR file, but now we also require HTML and JS links for visualization. Is there an alte ...

Choose the CSS class based on the content provided

Help needed with CSS issue. I want to target the <tr> element's class using Bootstrap classes like .success or .danger. In my Vue.js project, the status name in my object does not align with the .success or .danger classes, but I still need to ...

utilize jQuery to include a tag into every div

This is the current sample: <div class="main-wrap"> <div class="inner-wrap"> some example text here <span> <a href="1">test1</a> </span> </div> <div class="inner- ...

Tips for transferring a value from a function in ASPX to a CS file

I seem to be overlooking a small detail. I have a dropdown list (DDL) and a function in my C# file. I want to pass the 'value attribute' of a selected DDL option to my function, but I can't seem to retrieve the value attribute. I checked the ...