Is it possible to disable a function by clicking on it?

I currently have a website that is utilizing the following plugin:

This plugin enables an image to be zoomed in and out through CSS transforms, with default controls for zooming in and out.

My goal is to incorporate a reset button that returns the image to its original state before any zooming occurred.

Here's what I have tried so far...

$('.reset').on('click',function(){
  $('.zoomer-holder').css(
    'transform','translate3d(-50%, -50%, 0px) scale(0.2525, 0.2525)'
  );
});

While this code works perfectly on a jsfiddle demo, it fails to function alongside the zoomer plugin on my site. It seems like the plugin is preventing any alterations to the image.

If anyone has insights into why this might be happening, please share your thoughts.

Check out the JsFiddle demo here: http://jsfiddle.net/fxuqqgLh/1/

Answer №1

It appears that the plugin utilizes an animation loop which repeatedly calls a _render() function to manage zooming and panning of the held images. This render function is called continuously - possibly several times per second:

function _render() {
    for (var i = 0, count = $instances.length; i < count; i++) {
        var data = $instances.eq(i).data("zoomer");

        if (typeof data === "object") {
            // Update image and position values
            data = _updateValues(data);
            data.lastAction = data.action;

            // Update DOM
            if (transformSupported) {
                var scaleX = data.imageWidth / data.naturalWidth,
                    scaleY = data.imageHeight / data.naturalHeight;

                data.$positioner.css(_prefix("transform", "translate3d(" + data.positionerLeft + "px, " + data.positionerTop + "px, 0)"));
                data.$holder.css(_prefix("transform", "translate3d(-50%, -50%, 0) scale(" + scaleX + "," + scaleY + ")"));
            } else {
                data.$positioner.css({
                    left: data.positionerLeft,
                    top: data.positionerTop
                });
                data.$holder.css({
                    left: data.imageLeft,
                    top: data.imageTop,
                    width: data.imageWidth,
                    height: data.imageHeight
                });
            }

            // Run callback function
            if (data.callback) {
                data.callback.apply(data.$zoomer, [
                    (data.imageWidth - data.minWidth) / (data.maxWidth - data.minWidth)
                ]);
            }
        }
    }
}

The _render() function relies on properties such as data.imageWidth and data.imageHeight to determine the image size in each animation cycle. These properties are defined by data.targetImageWidth and

data.targetImageHeight</code. The plugin gradually adjusts the width/height properties towards the targetWidth/targetHeight properties to achieve the animation effect.</p>

<p>To understand how the plugin functions, try setting a breakpoint at this line within <code>_render()
:

var scaleX = data.imageWidth / data.naturalWidth,

Then experiment with different values for imageWidth, imageHeight, targetImageWidth, and

targetImageHeight</code using the javascript console. You can observe the behavior of the plugin.</p>

<p>If you wish to create a 'reset' button, you will need to modify the <code>data
object of the zoom plugin programmatically instead of directly manipulating the css. Consider downloading and extending the plugin's source code, focusing on the controls object under options:

var options = {
    callback: $.noop,
    controls: {
        position: "bottom",
        zoomIn: null,
        zoomOut: null,
        next: null,
        previous: null
    },
    customClass: "",
    enertia: 0.2,
    increment: 0.01,
    marginMin: 30, // Min bounds
    marginMax: 100, // Max bounds
    retina: false,
    source: null
};

Answer №2

$( ".clear-button" ).click(function() {
  //Your custom code goes here
});

Have you considered using this alternative method:

$('.clear-button').on('click',function(){
  $('.zoomer-container').css(
    'transform','translate3d(-50%, -50%, 0px) scale(0.2525, 0.2525)'
  );
});

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

How to Troubleshoot jQuery AJAX Not Sending JSON Data

I've been attempting to make an ajax request, but it keeps returning with an error response. $('form#contactForm button.submit').click(function () { var contactName = $('#contactForm #contactName').val(); ...

extracting URL parameters using AJAX

I have successfully created an AJAX request using the GET method, passing variables to the URL and receiving a response. Now, I need to retrieve the current URL variables by clicking on a newly created button in order to proceed with further processing. Th ...

PHP threading on AJAX call: optimizing performance in web applications

hello.php My file, hello.php, is designed to respond to AJAX calls made by users using JavaScript. Now, imagine two users, A and B, sending their GET requests to hello.php at the exact same time. In this scenario, hello.php includes code that will delay ...

Rendering json data in jquery

Is there a way to load a .json file from the assets folder into a jquery script within a grails application? Below is the jquery code snippet I have written to handle this: let dropdown = $('#banks'); dropdown.empty(); dropdown.append(' ...

How to Automatically Close an Ajax Modal Popup After Executing Code in ItemCommand in ASP.Net

I am currently facing an issue with closing a ModalPopup after a code sequence is executed. The situation at hand involves coding a filebrowser for the company and everything seems to be working fine except for the downloading of files. I have implemented ...

Utilize the three.js library within a Vue component by importing it and incorporating its

Can someone please help me understand the proper way to import and utilize the three.js library in a vue component? Despite my extensive research, it seems that most individuals use the following code line to import three.js into a vue component. However, ...

Is there a way to display my <i> tags inline without any issues?

I am facing an issue with my code and need assistance. I have two links that I want to display but my code doesn't seem to respond as expected. The first link is: https://i.sstatic.net/fryPH.png The second link is: https://i.sstatic.net/j849M.png A ...

Best practice for passing a variable argument in a JavaScript callback?

After searching the internet without success, I couldn't find the answer to my problem. The issue revolves around a function that I have: function ParentFunction (DataBase, Parameters) { for (k = 0; k < DataBase.length; k++){ var ...

Arranging a dropdown list of options in alphabetical order using Javascript

Could you assist me in sorting my select list alphabetically? Below is the code I currently have:- $.getJSON("php/countryBorders.geo.json", (data) => { $select.html(""); for (let i = 0; i < data["features"].leng ...

Using the PUT method in Node.js to set the ID

Need help with setting ID value from frontend apiRoutes.put('/intake', function(req, res) { Intake.findById({id, function(err, intake) { if (err) res.send(err); check : true; intake.save(function(err) { ...

Using both CASE and MATCH operators within an array in Neo4j's Cypher Query Language (

Using the code snippet below, I am attempting to retrieve all details related to user data where the checked value is either 1 or 0. I have noticed that 'WHERE flight.checked IN check' does not seem to be properly working. Is it appropriate to u ...

Why is my NextJs app loading slowly on Safari but quickly on Chrome?

Currently, I am in the process of developing a web app using nextjs. I have encountered some issues with linking to pages, particularly the home page which contains multiple svgs and images. The performance lags when using Safari, as it does not show a loa ...

Determining age with calculator plugin using jQuery

I have two sets of dates (selected via inputs/selects in the format mm/dd/yyyy) on my page. I want a specific readonly text field to display the age in months, calculated based on those two dates, after a different select field (not part of the date set) ...

Using AJAX to query a database and updating a div tag with the submitted form entries

I need assistance in setting up a webpage with an AJAX form. The idea is that upon submission, the form's values will be used to search and query a database for results, which will then be displayed in the same DIV as the form. Any guidance or help o ...

Sending the ID of a mapped button to a component

I need help with my React mapping function that displays a series of cards, each with its own button to open up a dialog box. Right now, I'm struggling to pass the unique ID from each object to the correct dialog box. Instead, all IDs are being passed ...

What causes duplicate packages to appear in Bower at times?

There appears to be two identical packages available for the Sugar javascript library, sugar and sugarjs. Are these packages interchangeable or are they being maintained separately by different individuals? ➔ bower info sugarjs bower sugarjs#* ...

What is the process for modifying the popups associated with a polygon object?

As of now, every time I click on the map, a popup shows up with the name of the country based on a geoJSON file containing multi-polygon lnglat coordinates that outline the borders of each country. This method saves me from manually inputting each country& ...

What is the best way to send AJAX post data to a Node.js server?

I am currently facing an issue with passing a unique ID object back to the server side using Ajax after making an API call. I need help figuring out what might be going wrong in my code. This is the client side code snippet where I loop through a JavaScri ...

Warning: An unhandled promise rejection occurred while using agenda

I encountered an UnhandledPromiseRejectionWarning while running my project which utilizes the agenda package. Here is the code snippet: agenda.define('transferDBField', (job, done) => { if (this.tPrice) { this.prices.push(this.tP ...

Dynamic Interactive Content with AJAX

Imagine if all the forms in your application followed this structure: <div id="result_messages"></div> <form action="/action"> <!-- all the form --> </form> Here's an example of what a submit button for this form might ...