Focusing in on a PARTICULAR SECTION of the picture

My website has a unique concept - comparing two articles side by side. One of the articles is mine, while the other is displayed alongside it.

To capture entire pages for comparison, I utilize Google's GoFullPage feature to take screenshots.

The goal is to zoom in on each paragraph individually so that viewers can see corresponding paragraphs from both articles clearly.

In my attempts to achieve this effect, I initially used offset: path() with a transition on the width attribute. However, this resulted in an unintended rotation of the screenshot, displaying it horizontally regardless of the width attribute adjustment.

Subsequently, adding a transition to the top: 0; attribute came close to the desired effect.

Finally, I experimented with applying a transition using two negative margins: margin-top: -20% & margin-bottom: -20%. Though successful in the upper areas of the screenshot, this method posed a challenge as the negative margin values persisted.

Despite various attempts with negative margins, none seemed to produce the desired zoom effect effectively.

Looking into alternative solutions, I discovered the existence of a zoom property. Could this potentially offer the effect I am seeking? Perhaps JavaScript could provide a better alternative?

Below is the code snippet:

body {
  overflow-x: hidden;
}

.drag-container {
  display: flex;
  min-height: 100vh;
}

[class^="panel"] {
  padding: 0px 0px;
  background-color: white;
}

.panel-one {
  width: 48.9%;
}

.panel-two {
  flex: 1;
  width: 52.1%;
}

.dragbar {
  position: relative;
  padding: 2px;
  cursor: pointer;
  background-color: rgb(25, 0, 75);
}

.slider {
  position: relative;
  z-index: 9;
  cursor: pointer;
  /*set the appearance of the slider:*/
  width: 40px;
  height: 40px;
}

.reference-image {
  position: relative;

  width: 100%;
  height: 100%;

  transition-property: width , top , margin-top;
  transition-duration: 1s;

  margin-top: 0;
  margin-bottom: 0;
}

.reference-image:hover {
  width: 179.1%;

  margin-top: -20%;
  margin-bottom: -20%;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <link rel="stylesheet" ; href="COPY.css">

  <title>History of Africa</title>

  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;

      text-align: center;
    }
  </style>

</head>

<body>
  <!-- DRAG BAR (IMAGE) -->
  <div class="drag-container">
    <div class="panel-one" ; id="drag-left">

      <img src="https://i.sstatic.net/QSr5pLZn.png" ; style="display: block; width: 100%;">

      <h1 style="text-decoration: underline;">Safkfsdf Akslefos Alpsdfd</h1>

      <br>
      <br>

      <p>
        Lorem ipsum dolor sit amet consectetur, adipisicing elit. Ullam reprehenderit modi eius
        numquam.Quia saepe nulla aliquid nesciunt et a pariatur expedita mollitia. Suscipit
        necessitatibus temporibus architecto ea rerum eveniet.
        Vitae quis sint tenetur impedit corrupti esse error amet minima enim. Eos quas similique
        aperiam itaque autem. Veritatis optio deleniti, deserunt animi soluta, nam ab aut maxime
        inventore quis voluptate.
        Ipsam, corporis earum. Ipsa quasi ipsum eius, dolor dolore assumenda! Eum quod fugit iste
        dignissimos exercitationem libero, numquam reprehenderit, rerum totam, delectus expedita
        voluptas nam unde! Magnam corrupti ratione amet.
        Quaerat quasi qui pariatur earum nobis velit, nemo consectetur laborum tenetur sed! Modi
        ipsa temporibus mollitia dolor inventore. Sapiente molestias alias nesciunt! Dolor non
        quas soluta eaque repellendus enim ipsam.
      </p>
    </div>

    <div class="dragbar" ; id="dragbar">
      <div class="slider"></div>
    </div>

    <div class="panel-two" ; id="drag-right">

      <img class="reference-image" ; src="https://i.sstatic.net/jN8q6WFd.png" ; width="100%" ; height="100%">
      
    </div>
  </div>

</body>

</html>

Answer №1

To create zoom effects using a background image, adjust the background-size and background-position.

const d2 = document.querySelector('.d2')
document.addEventListener('click', evt => {
  if (!evt.target.dataset.index) return
  d2.className = "d2"
  switch(Number(evt.target.dataset.index)) {
    case 1:
      d2.classList.add('zoom','cyan')
      break
    case 2:
      d2.classList.add('zoom','yellow')
      break
    case 3:
      d2.classList.add('zoom','green')
      break
    case 4:
      d2.classList.add('zoom','blue')
      break
    case 5:
      d2.classList.add('zoom','red')
      break
    case 6:
      d2.classList.add('zoom','navy')
      break
  }
})
body {
  margin: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.d1 {
  padding: 1em;  
}

.d2 {
  height: 100vh;
  background: url(https://i.sstatic.net/jN8q6WFd.png);
  background-size: 30%;
  background-repeat: no-repeat;
  background-position: center;
  transition: 0.5s;
}

.d2.zoom {
  background-size: 150%;
}

.d2.cyan {
  background-position: right 16%;
}

.d2.yellow {
  background-position: right 30%;
}

.d2.green {
  background-position: right 44%;
}

.d2.blue {
  background-position: right 58%;
}

.d2.red {
  background-position: right 72%;
}

.d2.navy {
  background-position: right 86%;
}
<div class="d1">
  <p>Explore different sections by clicking on the buttons below</p>
  <button data-index="0">Reset</button>
  <button data-index="1">Cyan</button>
  <button data-index="2">Yellow</button>
  <button data-index="3">Green</button>
  <button data-index="4">Blue</button>
  <button data-index="5">Red</button>
  <button data-index="6">Navy</button>
</div>
<div class="d2"></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

JavaScript bug with URL encoding in Internet Explorer 11

I am encountering an issue with Internet Explorer 11 (IE 11) when attempting to call a JavaScript URL function. The problem lies with the URL parameter value, which is in Unicode format but the result displays as ????? instead of Unicode characters. Belo ...

Is it possible for an Express app.get() function to identify and handle requests for specific file extensions

Is it possible for me to manage requests for any .html file type? For example, can I achieve something like this: // server.js app.get('/*.html', (req, res) => { // perform certain actions when an html file request is made }); ...

Delivering objects from controller in AngularJS

I'm currently working on a project where I need to retrieve objects from the controller. Here's a snippet of my code: score.component.js: angular.module('score').component('score',{ templateUrl : 'app/score/score.t ...

Simulating a JavaScript constructor using Sinon.JS

I need to write unit tests for the ES6 class below: // service.js const InternalService = require('internal-service'); class Service { constructor(args) { this.internalService = new InternalService(args); } getData(args) { let ...

How can I transfer data from a C# code to a JavaScript file in asp.net?

I am faced with the task of transferring values from a C# class to a JavaScript file. To achieve this, I have generated a string in C# which contains the values of the list as follows: count = 0; JString = "["; for(i=0; i<x; i++) { JString += "{Sou ...

Differences Between APP_INITIALIZER and platformBrowserDynamic with provide

I've discovered two different approaches for delaying an Angular bootstrap until a Promise or Observable is resolved. One method involves using APP_INITIALIZER: { provide: APP_INITIALIZER, useFactory: (configService: ConfigurationService) => ( ...

Arranging JavaScript object by object properties (name)

Can anyone assist me with my training? I am currently learning JavaScript (Js) and TypeScript (Ts) by working with an external public API. After successfully fetching and displaying my data, I now want to implement sorting functionality. My goal is to sor ...

Failed commitments in Protractor/WebDriverJS

WebdriverIO and Protractor are built on the concept of promises: Both WebdriverIO (and as a result, Protractor) APIs operate asynchronously. All functions return promises. WebdriverIO maintains a queue of pending promises known as the control flow to ...

Connecting different jQuery methods to create a chain

From my understanding of jQuery chaining, the first method in the list must complete before the next method executes. Here is an example: $.fn.reportZebraStriper = function(options) { console.log('reportZebraStriper()'); return true; } ...

Display the current language in the Vue language dropdown

My component is called DropdownLanguage.vue Goal: I need to show the current active language by default in the :text="selectedOptionDropdown" attribute. For example, it should display "English" which corresponds to languages.name. I'm struggling with ...

PostgreSQL dynamic query with Node.js

I am currently developing a note-taking app using REACT. My focus is on tracking only the changes made by the user to the note, rather than the current state of the note. For properties that have not been altered, I intend to send them as an empty string ...

"Enhance Your Website with Various Hover Effects Using CSS across Multiple Elements

Has anyone experienced trouble with making the hover effect work in my onHover class and applying a display effect to span.box? Any ideas on how to fix this? .onHover { display: block; width: 200px; height: 20px; background: green; } .onHover:ho ...

What is the best way to horizontally align Font Awesome icons in the center?

In my table, I have a Font Awesome icon that I'm trying to align left with text and center the icons. I attempted to center the <i> element but it didn't work as expected: Here is the HTML code: <td><i class="icon-ok"></i&g ...

Enhance the impact of "dialogs" to the fullest extent or minimize it to achieve the

How can I position the minimized dialog on the bottom of the div when appending dialogs next to each other in a FB messaging system? To achieve a Facebook messaging effect, the titlebar must go down when minimizing/maximizing the dialog. Perform the follo ...

Challenges with form validation

Hello everyone, I'm a newbie to JS and struggling with my code. It seems like everything should work, but it just won't. The issue seems to be with the phone number form validation. I've written code that, in theory, should do the job, but ...

Sidebar content alignment vertically

Struggling with aligning items in a sidebar, specifically regarding the fixed footer and the overflow of the main sidebar container. Trying to achieve a layout where the scrollable element stays within the designated space. Current setup includes: ...

Is the Three.JS camera update causing issues with the shader?

Attempting to replicate the Bubble shader from https://github.com/stemkoski/stemkoski.github.com/blob/master/Three.js/Bubble.html, but encountering issues due to outdated code. The example should refract whatever is behind it, like this: https://i.sstatic ...

What is the method to group a TypeScript array based on a key from an object within the array?

I am dealing with an array called products that requires grouping based on the Product._shop_id. export class Product { _id: string; _shop_id: string; } export class Variant { variant_id: string; } export interface ShoppingCart { Variant: ...

Display a message in jQuery when the same option is chosen more than once

I need help with my form that has an input text field and a select dropdown. Here is the markup: <div id="form-wrap" style="width:500px; margin: 0 auto;"> <table> <tr> <th width="55%">Service Name</th> ...

The Threejs Blender exporter is exporting in an incorrect format

I'm attempting to convert a blender model into a threejs JSON format using the provided blender exporter. However, when I try to parse the JSON file, I encounter an error: Uncaught TypeError: Cannot read property 'length' of undefined The ...