JavaScript has encountered a syntax error

When working on an animation in javascript, I encountered a problem that I can't seem to identify. I am attempting to make the pan function work with the "mover" function, but it seems like either I am not using the properties correctly within the "transformOrigin," or I have missed a step somewhere. Additionally, no errors are appearing on the console.

function changeImage(image) {
  document.getElementById("pb").src=image;
}

function zoomIn() {
  document.getElementById("pb").style.transform="scale(1.8)";
}

function zoomOut() {
  document.getElementById("pb").style.transform="";
}

function move(element) {
  document.getElementById("pb").style.transformOrigin=((event.pageX - element.offsetLeft) / element.width) * 100 + "% " + ((event.pageY - element.offsetTop) / element.height) * 100 + "%";
}
body {
  display: flex;
  flex-flow: row nowrap;
}
#big {
  width: 300px;
  height: 250px;
  overflow: hidden;
}
#pb{
  width: 300px;
  transition: transform 0.25s ease;
}
#thumbnail {
  width: 60px;
  overflow: hidden;
}
#thumbnail img{
  width: 60px
}
#thumbnail img:hover {
  opacity: 0.5;
  transition: all 300ms ease;
}
<div id="thumbnail">
<a href=""><img src="http://www.cosmoscreativeagency.com/images/1.jpg" onmouseover="changeImage('http://www.cosmoscreativeagency.com/images/1.jpg')" ></a>
<a href=""><img src="http://www.cosmoscreativeagency.com/images/2.jpg" onmouseover="changeImage('http://www.cosmoscreativeagency.com/images/2.jpg')" ></a>
<a href=""><img src="http://www.cosmoscreativeagency.com/images/3.jpg" onmouseover="changeImage('http://www.cosmoscreativeagency.com/images/3.jpg')" ></a>
<a href=""><img src="http://www.cosmoscreativeagency.com/images/4.jpg" onmouseover="changeImage('http://www.cosmoscreativeagency.com/images/4.jpg')" ></a>
</div>

<div id="big">
<img src="http://www.cosmoscreativeagency.com/images/1.jpg" id="pb" onmouseover="zoomIn()" onmouseout="zoomOut()" onmousemove="move(this)">
</div>

Answer №1

Make sure to allow this to go through.

Then

function moveElement(item) {
  document.getElementById("pb").style.transformOrigin=((event.pageX - item.offsetLeft) / item.width) * 100 + "% " + ((event.pageY - item.offsetTop) / item.height) * 100 + "%";
}

Also

... onmousemove="moveElement(this)" ...

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 reason border-box does not function properly on inline-block elements?

Demo: http://jsfiddle.net/L5jchnpm/ I've encountered an issue where I believed that using display: inline-block would make elements act as both inline and block elements. Additionally, I thought that setting box-sizing: border-box would adjust the w ...

Why am I unable to alter the variable value within the callback event?

Exploration of Request Handling POST request To /api/endpoint headers: standard body: data=test123 POST response From /api/endpoint headers: standard body: data=test123 expectation(NOT MET): Show the request body content in the console. reality(FRU ...

Tips for integrating both client-side and server-side validation techniques in your web application

After conducting some research, I have come across information indicating that it is feasible to implement both client-side and server-side validation simultaneously. However, my focus is not solely on learning JavaScript; I am also interested in utilizi ...

Jquery failing to function properly when scrolling

I have been attempting to implement a feature where an element changes its position to fixed after scrolling past a certain point. However, no change occurs when I scroll. In the <head> section of my code, I have included <script src="stiler/jquer ...

Struggling with CSS, seeking improvements to align with my previous coding style

After spending a considerable amount of time working on my game, I made the decision to change my navigation bars to buttons. However, I'm facing issues while trying to finalize the style that I had previously. Here is the old code fiddle: https://js ...

Unselected default option in Angular 4's select dropdown

My goal is to use Angular to retrieve a value from a variable and display it as the first option in a select element, while keeping the rest of the options below static. The issue I am facing is that even though Angular is fetching the data successfully, t ...

Permanently removing artwork from the Canvas

I am facing an issue with my canvas drawing function. Whenever I clear the drawings on the background image by clicking a button, the old drawings reappear when I try to draw again. How can I permanently delete the cleared drawings so that I can start fr ...

Save the currently active index of the mySwiper element even after the page is

After clicking through the carousel, I want to be able to store the current index and slide back to it after a page refresh. Is there a way to save this value in a variable so that I can use the mySwiper.slideTo() method to return to the last index? In si ...

Positioning of DIV elements in relation to each other

I'm currently enrolled in Codecademy's HTML & CSS course and I'm finding the topic of positioning a bit perplexing. Here is an example of my HTML file: <!DOCTYPE html> <html> <head> <style> div { pos ...

Creating a process to produce a random number and send it directly to an automated email

I'm currently utilizing a form builder from jqueryform.com to construct a registration form. My goal is to have each registered user assigned with a unique account number, which will be a randomly generated 6-digit number. Additionally, I want the pro ...

Getting dynamic variables in the `getStaticProps` function of NextJS can greatly enhance

I am working on utilizing getStaticProps in order to fetch data based on a variable. Here is a sample code snippet: export async function getStaticProps() { const res = await fetch(localWordpressUrl, { method: 'POST', headers: { 'C ...

adjusting the color of ion-button when hovering over the cancel button

I'm working on a button bar for my app and I want the color of the button to change based on its state (false, true). Currently, the button starts out green, turns light green when hovered over, and becomes white when clicked. Once I click it, the bu ...

Is there a way to implement the border-box property for Internet Explorer versions 6 and

Similar Question: How to implement box-sizing in IE7 Anyone know a method or workaround to apply box-sizing:border-box; in IE6 and IE7? Even just for IE7? ...

identify when the bottom of a container is reached during scrolling through a window

On my website, I have a section with products displayed in the center of an HTML page. I am looking to implement an AJAX call that will load additional products when the user reaches the bottom of this product container by scrolling down. How can I detec ...

Troubleshooting Problems with CSS `transform` in JQuery UI's `Slide` Transition

While implementing JQueryUI's slide transition on an element with a CSS transform, I encountered an issue where the top half of the element gets hidden during the animation. Is there a way to tweak either my JQueryUI animation or CSS to avoid this pro ...

Customizing the formatting of Angular's ui-select2 NoMatches message within a directive

I have a multiple select in a directive template and I want to customize the message that appears when no matches are found. The documentation on suggests overriding the formatNoMatches method for this purpose. This is the select element in my directive& ...

Using the power of JavaScript to iterate through elements with the

Looking for a way to integrate JSON data into your simple bootstrap page? Here's a script that might help: Take a look at the following script: var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && ...

Enforcing object keys in Typescript based on object values

I'm looking to design a structure where the keys of an object are based on values from other parts of the object. For example: type AreaChartData = { xAxis: string; yAxis: string; data: { [Key in AreaChartData['xAxis'] | AreaChart ...

What are the steps for implementing Babel in a CLI program?

Currently, I am working on developing a CLI program in Node using Babel. While researching, I came across a question on Stack Overflow where user loganfsmyth recommended: Ideally you'd precompile before distributing your package. Following this ad ...

Error encountered: Exceeded maximum update depth in Material UI Data Grid

Encountering an error or warning when inputting rows in the table that is causing the screen to freeze. Warning: Maximum update depth exceeded. This issue can arise when a component triggers setState within useEffect, but useEffect doesn't have a de ...