Tips for automatically disabling cloudzoom based on image width

I'm currently utilizing cloudzoom with the given markup:

<div id="container">
  <img id="main-image" class="cloudzoom" src="/img/image1.jpg" data-cloudzoom="variableMagnification: false, zoomOffsetX: 0, zoomPosition: 'inside', zoomImage: '/img-zoom/image1.jpg" />
  <div id="thumbnail-images">
    <img class='cloudzoom-gallery' src="/img/image2.jpg" data-cloudzoom="useZoom: '.cloudzoom', image: '/img/image2.jpg', zoomImage: '/img-zoom/image2.jpg'">
    <img class='cloudzoom-gallery' src="/img/image3.jpg" data-cloudzoom="useZoom: '.cloudzoom', image: '/img/image3.jpg', zoomImage: '/img-zoom/image3.jpg'">
  </div>
</div>

To initialize cloudzoom, I am using this code:

$('#container', context).once('initiateCloudzoom').each(function () {
    CloudZoom.quickStart();
});

Although the current implementation is functioning properly, my inquiry is:

How can I deactivate cloudzoom if the main image's width falls below X pixels?

In addition, how can I toggle the enable/disable state of cloudzoom when clicking on a thumbnail based on the same image width condition once the image has been swapped?

Thank you in advance.

Answer №1

To deactivate the zoom feature, set the disableZoom value to auto. This will only disable zoom if the zoomed image is equal to or smaller than the original image. Keep in mind that if you have magnification levels greater than 1, the zoom function will remain active.

 <div id="container">
  <img id="main-image" class="cloudzoom" src="/img/image1.jpg" data-cloudzoom="variableMagnification: false, zoomOffsetX: 0, zoomPosition: 'inside', zoomImage: '/img-zoom/image1.jpg'" />
  <div id="thumbnail-images">
    <img class='cloudzoom-gallery' src="/img/image2.jpg" data-cloudzoom="useZoom: '.cloudzoom', image: '/img/image2.jpg', zoomImage: '/img-zoom/image2.jpg', disableZoom:'auto'">
    <img class='cloudzoom-gallery' src="/img/image3.jpg" data-cloudzoom="useZoom: '.cloudzoom', image: '/img/image3.jpg', zoomImage: '/img-zoom/image3.jpg', disableZoom:'auto'">
  </div>
</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

What is the best way to implement horizontal scrolling in a div with the "inertia" style?

I recently added horizontal scrolling to my website wikiprop.org, following a tutorial from another website. However, I noticed that my scroll does not have the same inertia/momentum effect where it continues scrolling after a swipe and gradually slows dow ...

What could be causing this strange striping effect in the radial gradient?

What causes the striped effect in the radial gradient code provided on this website: click here to view body { background: rgba(216,215,221,1); background: -moz-radial-gradient(center, ellipse cover, rgba(enter code here216,215,221,1) 0%, rgba(0,9 ...

using jquery to select multiple checkboxes with not() and contains()

I have a situation where I need to read multiple checkboxes and combine their values into a comma-separated string. Using this string, I aim to hide certain elements in a table that do not contain the specified values from the checkboxes. Each checkbox cor ...

Minimization tools for compressing CSS and JavaScript documents

After deploying my application, I noticed that the loading time has significantly increased. Is there a way to compress CSS and JS files? I include only the necessary code in each page and occasionally use minified versions of JS. Thank you. ...

Having trouble implementing font css file in Reactjs

When working with Reactjs (Nextjs), every time I try to incorporate "css" into my project, I encounter the following error on my screen: Module not found: Can't resolve '../fonts/fontawesome-webfont.eot?v=4.7.0' How can I solve this issue? ...

Jquery functions are only effective when placed within the header.php file

While I've been diving deep into jQuery this week, I have a website to wrap up and am in desperate need of a solution for a problem that has consumed the last eight hours. Scenario I am working with an ajaxed WordPress theme which I am currently cus ...

What is the best way to transfer the array from my function and have it returned?

I've been struggling to successfully pass my array to an external function. Can anyone help me with this? You can find the code that I'm working on in jsbin: https://jsbin.com/kugesozawi/edit?js,console,output. The expected result should be passe ...

javascript tabs not functioning as expected in HTML

I am currently putting the finishing touches on a basic website for a project I'm involved in. The site features two tab controls - one on the right side of the page and the other on the left. Each control has 3 tabs that, when clicked, display differ ...

After clicking, revert back to the starting position

Hey there, I have a question about manipulating elements in the DOM. Here's the scenario: when I click a button, a div is displayed. After 2 seconds, this div is replaced by another one which has a function attached to it that removes the div again. ...

Adding Google Map V3 markers dynamically through jQuery

I have been using jquery and the Google Maps V3 API to dynamically add markers to my Google Maps. Whenever I click on the button search_button, an AJAX request is sent to the server, which returns a JSON array of LatLng values corresponding to the results. ...

Displaying and concealing a div based on the scroll position

I have implemented a script that hides a div and then shows it when I scroll past a certain point on the page. It is working correctly, but once I scroll back up to the top, the div remains visible. Can someone suggest a modification to the code that will ...

Java script pop-up notifications always show up

This Text Goes Above the Form <?php require_once "core-admin/init-admin.php"; if( !isset($_SESSION['admin_username']) ){ $_SESSION['msg'] = 'page cannot be opened'; header('Location:admin_login.php&ap ...

Single input results in array output

I have a pair of items in this array list. $.each(data.recalls,function(i) { var recall = data.recalls[i].nnaId; var description = data.recalls[i].remedyDescription; console.log(recall); console.log(description); $('textarea[name= ...

Enhanced User Experience Through Triggered Content Recommendations based on Scrolling Patterns

When a user scrolls beyond a certain point on a webpage, I would like a recommended content popup to slide out from the right side at the bottom of the page. An excellent example can be seen on USAToday where a blue recommended box appears as you scroll d ...

How to resolve CORS error when using custom request header in Django with JavaScript and redirecting to OPTIONS request?

I am currently working on building an API library using Django. This API will be accessed by javascript, with the Django-API and javascript running on separate servers. The Django API library requires a custom request header from the javascript front end, ...

Arrange the input fields on a single line in Rails for a clean and organized layout

Below is a Rails code snippet for input fields. Name:-<%=text_field_tag "specification[name1]","",:class=>"autocomplete form-control"%> <br/> Value:-<%=text_field_tag "specification[value1]","",:class=>"autocomplete form-control"%> ...

The HTML modal closing button is unresponsive and the contents inside are misaligned, causing functionality issues

I've searched through similar questions, but none of the suggested solutions seem to work for my issue. The problem I'm facing is that the closing button on my modal isn't functioning properly and the content inside it is not aligning corre ...

Ways to reduce the width of a flex box

I am facing an issue with my main container where I have two items placed on the same line. Item 1 is an image linked to a URL and it should be positioned at the far left of the container. On the other hand, item 2 contains a font awesome icon that needs t ...

What is the best way to align two items where one is centered and the other is positioned to the left?

In an attempt to customize a chat call to action, I am looking to have an icon aligned to the left and some centered text. Here is an example of how I envision it: [ @ Text aligned in center ] Here is what I have tried so far: .icon{ justify-self: ...

The dropdown menu is not appearing in the correct position when clicked

https://i.stack.imgur.com/fMyZQ.jpg Hello there, this link appears normal before clicking on it. But once clicked, it moves to the top of the page like so: https://i.stack.imgur.com/yZ0R0.jpg You can clearly see the difference. I have also provided the c ...