Resize all types of content using a "zooming" container

Is there a way to create a magnifying effect without duplicating content and still keep the underlying elements clickable?

Check out this jsfiddle example

I am looking for a solution to scale the underlying div within the magnifying zoom without cloning it. Can the pixel ratio be altered within the large div to achieve a localized zoom effect? Is this feasible?

NOTE: A similar scenario is discussed in this question, but I want to avoid cloning and hiding content.

Example HTML:

  <div class="magnify">
    <img class="small" src="http://placehold.it/300x150" width="400"/> 
    <a href="#" target = "_blank" style="position:absolute;left:50%;top:40%;width:20px;height:20px;border:5px solid red; border-radius:10px">Demo clickable link</a>
  <div class="large"></div>
  </div>
  <p id="demo"></p>

Corresponding CSS:

   .magnify {width: 900px; margin: 50px auto; position: relative;border:1px solid red;}
   .small { display: block; width:900px;}

   .large {
    width: 275px; height: 275px;
    position: absolute;
    border-radius: 100%;

    pointer-events:none; /* allows user to click through the div to 
                     underlying content */   
    }

JavaScript Functions:

$(document).ready(function(){

$(".magnify").mousemove(function(e){

    x = e.clientX;
    y = e.clientY;
    coor = "Coordinates: (" + x + "," + y + ")";
    document.getElementById("demo").innerHTML = coor;


    var magnify_offset = $(this).offset();
    var mx = e.pageX - magnify_offset.left;
    var my = e.pageY - magnify_offset.top;

    //fade out the glass if the mouse is outside the container
    if(mx < $(this).width() && my < $(this).height() && mx > 0 && my > 0)
    {
        $(".large").fadeIn(100);
    }
    else
    {
        $(".large").fadeOut(100);
    }
    if($(".large").is(":visible"))
    {
        //move the magnifying glass with the mouse
        var px = mx - $(".large").width()/2;
        var py = my - $(".large").height()/2;

        $(".large").css({left: px, top: py});
    }
})
})

Answer №1

When working with scaling HTML elements inside a div, it's crucial not to overlook the "scale transform + duplicate" step.

If you're aiming to display just an image, utilizing CSS background position can work like magic, but be prepared for requiring a larger image size.

An alternative solution is exploring the CANVAS ZOOM technique.

By the way, attempting to "...change the screen pixel ratio within the bounds of the outer div..." is simply impossible.

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

What is the best way to prevent one react audio player from continuing to play when starting another?

I'm struggling to implement state tracking to determine which song is currently playing. I'm unsure about the parameters to pass into the React Audio Player and where to set the state. Can anyone help with this? This is the code for the entire co ...

Struggling to find a solution for altering font color with jQuery while creating a straightforward menu

I'm having trouble changing the color of the active button pressed to "color:white;"... Here is the link to the jsfiddle: http://jsfiddle.net/wLXBR/ Apologies for the clutter in the file, my css is located at the bottom of the CSS box (Foundation cod ...

Is there a way to adjust the height relative to the viewport in Bootstrap 5 for values other than 100?

Attempting to create a new type of div using a custom stylesheet with minimal non-bootstrap css. I am trying to convert each style rule from my django static files CSS into a bootstrap class, but I am stuck on viewport-based sizing. Prior to discovering t ...

Ways to extract information from a JSON request

Hey there, I'm new to this and still figuring things out. I'm looking to extract data from the following: { "list": [ { "brewery":"Strangeways", "beer":"Albino Monkey" }, { "brewery":"St. Bernardus", "beer":"Pater 6" } ] } Here' ...

Trying out an ajax request in React by clicking a button

I have been working on testing a simple Login component that involves filling out an email and password, then clicking a button to log in. When the login button is clicked, it triggers an ajax post request using axios. I am interested in testing both happy ...

Styling CSS for HTML links

I am encountering an issue with a CSS hover effect on an image that is also a hyperlink to another website. The CSS styling for the hover effect seems to be interfering with the functionality of the HTML hyperlink. The image in question is aligned with ot ...

Ways to showcase angular scope data within a placeholder while avoiding the use of angular expressions

Initially, I utilized angular expressions {{value}} to present values within elements. However, upon noticing that unrevealed expressions continue to display on the front end during loading delays, I switched to using ng-bind. <div> <h1>Hell ...

Add JSON elements to an array

Looking for help! {"Task": [Hours per Day],"Work": [11],"Eat": [6],"Commute": [4],"Sleep": [3]} Need to add these items to a jQuery array. I've attempted using JSON.parse without success. Typically, I can push parameters as follows: MyArr.push([& ...

Eliminate HTML TAG entries from the input form

My issue is that when I try to type a comma, it does not allow me to do so. How can I add other characters like <, >, /, \, etc? $("#in1").keypress(function (evt) { if (String.fromCharCode(evt.which) == ",") return false; }); < ...

Passing the hex code value of the background-color to the .text() function

My goal is to dynamically read the hexadecimal code from the <span> tag and set it as the background color of the same tag using jQuery. Currently, I have code that achieves this with specific variables, but I want to make it more dynamic. $(docum ...

I am having trouble with my :hover selector being interrupted by text, what steps should I take to resolve this

My issue revolves around an image with a hover effect that changes the box shadow color. However, there is text on the image that also changes when clicked, creating a problem where the area occupied by the text prevents the box shadow from displaying prop ...

Guide to altering the properties of child divs using JavaScript within the parent div

#va{ color:yellow; } #v{ color:pink; } <div id = "va"> <div id ="v">my name is </div> <div>khan</div> </div> After trying to use document.getelementbyid("va").style.color="yellow";, I found ...

Transferring a list from MVC ViewBag to JavaScript

I have a situation where I am passing a list of users from my controller to the view using the ViewBag. Now, I also need to pass this same list to the JavaScript on the page. One way I thought of doing this is by iterating through the list with a foreach l ...

What could be causing my function to exclude only the final element of the array when it returns?

My goal with the following code is to retrieve all items from item.children. However, I am puzzled as to why it's not returning the last item. After conducting multiple result logs and SQL verifications, I eventually pinpointed the issue in a specific ...

Encountering a Problem When Exporting a Class Using Require

I find myself struggling with a particular detail that eludes me. Despite exploring numerous suggested solutions found through Google, I am overwhelmed by the uncertainty of what actually works. Here is MyProject on Replit and the problematic class I&apos ...

Creating a list of definitions in the form of an HTML table using a multidimensional array in

Currently, I am tackling the following challenge: I must create a public static buildDefinitionList() method that produces an HTML list of definitions (using <dl>, <dt>, and <dd> tags) and then returns the resulting string. If the array c ...

Safari displays the contents of JSON files instead of automatically downloading them

I am facing an issue with a JavaScript code that generates a link to download a JSON file. The link is structured like this: <a href="data:text/json;charset=utf-8,..." download="foo.json">download</a> While the link works perfectly in Chrome ...

What could be causing such a significant impact on the row height in a CSS table when a tiny image is inserted next to an input box?

Currently, I am facing a unique challenge while setting up a form using CSS tables. The issue is best explained through a fiddle: http://jsfiddle.net/GdgV4/6/ In the third row, you'll notice that adding an image with a height less than the input box ...

Navigate through previous and next siblings in jQuery until a difference is found

Here's the issue: I have a div with multiple siblings positioned before and after it. For example: <div id="parent"> <div class="invalid"></div><!-- break iteration here !--> <div class="operand"></div> <div cl ...

Function that yields promise result

I need help figuring out how to make this recursive function return a promise value. I've attempted various approaches, but they all resulted in the search variable ending up as undefined. public search(message: Message) { let searchResult: strin ...