Explore the jQuery feature of Image Preview and modify the size of the Hover image

Can someone help me with a simple question?

I have been using the Easiest Tooltip and Image Preview Using jQuery and also tried out this example

Everything is working fine, but I need to adjust the hover image size in the tooltip. The current image is too big and I want to resize it to 200px x 200px. How can I achieve this?

This is the current style:

<style>
#preview{
    position:absolute;
    border:1px solid #ccc;
    background:#333;
    padding:5px;
    display:none;
    color:#fff;
}
</style>

And here is the Javascript:

this.imagePreview = function(){ 
    /* CONFIG */

        xOffset = 10;
        yOffset = 30;

        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result

    /* END CONFIG */
    $("a.preview").hover(function(e){
        this.t = this.title;
        this.title = "";    
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='preview'><img src='"+ this.href +"' alt='Image preview' />"+ c +"</p>");                                
        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .fadeIn("fast");                        
    },
    function(){
        this.title = this.t;    
        $("#preview").remove();
    }); 
    $("a.preview").mousemove(function(e){
        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px");
    });         
};

// starting the script on page load
$(document).ready(function(){
    imagePreview();
});

Lastly, here is the main part of the code:

<a href="1.jpg" /*class="preview"*/><img src="1s.jpg" alt="gallery thumbnail" /></a>

Answer №1

Insert

#display img {
  height:200px;
}

or modify

    $("body").append("<p id='display'><img src='"+ this.src +"' alt='Image display' />"+ count +"</p>");                                

to

    $("body").append('<p id="display"><img style="height:200px" src="'+ this.src +'" alt="Image display" />'+ count +'</p>');                                

or

    $("body").append('<p id="display"><img style="width:200px" src="'+ this.src +'" alt="Image display" />'+ count +'</p>');                                

depending on your preference for size limitations

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

Interested in concealing the delete and modify buttons of the formbuilder within the @formio/react component?

Reference Image const Formio = dynamic( () => import("@formio/react").then((module) => module.Form), { ssr: false } ); <Formio src={formJson} onSubmit={submitHandler} onChange={handleFormChange}/> In my Next.js project, I am us ...

What are some ways to create responsive elements using Bootstrap?

I'm looking for assistance in using bootstrap to divide a screen into 8 responsive parts (2 at the top, 2 in the middle, and 2 at the bottom). Can anyone help me with this? ...

Attempting to implement a multi-select input field using AJAX

I am attempting to save multi-select input using ajax in a Laravel application, but I keep encountering the following error: {message: "Function name must be a string", exception: "Error", …} Below is my Blade code: <select class= ...

"Utilizing Bootstrap for a Dynamic Display: Implementing Multiple Carousels with Multiple Images within

I have incorporated several Bootstrap carousels on one page, each with its own unique identifier. These carousels are generated dynamically based on user interactions, such as uploading images. My goal is to display 3 images at once in each carousel. I am ...

Load the page using AJAX and automatically scroll to the anchor within the loaded content

I want to achieve an automatic scroll to the beginning of a loaded page after using ajax to load it. Here is the code snippet I currently have: html <button class="btn btn-info btn-lg" type="button" id="photos"> <i class="fa fa-plus fa-5x">&l ...

Using an Ajax-jQuery request to fill in data for a table

Attempting to perform a web service call using the GET method from a URL with an ID. The specified URL is http://10.173.143.252:8181/cxf/crm/customerservice/customers/125. This URL returns a JSON response. {"id":125,"name":"John","password":"password","r ...

I never rely on the browser back button, I prefer to remain on the same page

Being new to Angular, I have come across the following code snippet: HTML template: <a href="" ng-click="goToCategories();">See categories</a> JS File: $scope.goToCategories= function () { CategoriesService.getCateg ...

Passing an ID in Next.js without showing it in the URL

I am looking to transfer the product id from the category page to the product page without showing it in the URL Category.js <h2> <Link href={{ pathname: `/product/car/${title}`, query: { id: Item.id, }, }} as={`/p ...

The preflight request for OPTIONS is receiving a 400 bad request error on the secure HTTPS

When making an Ajax call on the front end and calling a WCF service through Ajax, I encountered an issue with adding headers. As a result, a preflight OPTIONS request is triggered but fails due to the URL being blocked by CORS policy. I tried adding the f ...

Creating an Ajax form within qTip2

I have a table containing names, attributes, and comments for each record. I would like to implement a feature where users can view and update these comments via Ajax. My goal is to display the comments in a tooltip or modal when a link is clicked. The mod ...

Completing the pledge using ionic/ui-routing

I've encountered an issue with my promise not resolving as expected while using Ionic/ui-routing. This is the structure of my service: return { all: function () { $localForage.getItem('foo').then(function (bar) { re ...

JQuery is detecting an outdated file version

Currently, I am in the process of working on a project for my Raspberry Pi that focuses on gathering network speed information and then logging it in a local webserver. The script itself is functioning perfectly fine, however, I have encountered an issue w ...

Node.js error: Unable to find address when making an HTTPS request to an API

I am in the process of creating a dashboard, and I need to connect to an API to retrieve an Auth Token in order to send information using HTTPS protocol. I am utilizing Node.js for this task, but when I run my code, I encounter the following error on the p ...

Instructions for activating a button in the absence of any inputs

I need help enabling a button in angularjs based on whether any of the inputs are filled out. I was successful in disabling a button when only one input is checked, but how can I do this for all inputs affecting one button? This is what I've attempted ...

Using JavaScript to identify when a page is scrolling with smooth scrolling behavior and phasing out the scroll event for this purpose

My web page has a scroll event triggered by scrolling, but it also has links that smoothly scroll the content using scroll-behavior: smooth. I want to ensure that the scroll event only executes when scrolling occurs and not when a link is clicked. Below i ...

Communicating between iframes and parent elements via events

I'm trying to trigger an event in my iframe using the following code: $('body').trigger('my_event'); However, I want to bind this event on my main page that contains the iframe like this: $('iframe').find('body&ap ...

Moving ThreeJS model during animation (Retrieving model's position without callback function)

I'm in the process of creating a model that showcases the International Space Station orbiting around the Earth using threeJS. Everything is working perfectly except for updating the position of the ISS model. Currently, I have a sphere that orbits th ...

Revise the text while keeping the column content unchanged

Is it possible to change the text in a column without affecting the image using Jquery? Can this be achieved solely with Jquery without any modifications to the HTML code? Check out the demo $(".jsNoWrap").text("Change text"); <script src="https://a ...

Angular not rendering d3 uniquely when using *ngFor

I am currently working on integrating angular-d3-donut into my web application. Each should have its own SVG(donut). However, when I use *ngFor to generate multiple s with one SVG(donut) each, only one is being created and multiple SVG(donuts) are nested ...

"Enhance User Experience with a Bootstrap Dropdown Button Offering Block Level Function

I'm attempting to modify a bootstrap 3 dropdown button to fully utilize the width properties of .btn-block class. It appears that the dropdown button does not respond in the same way as regular buttons. Below is my current code: <div class="row"&g ...