Giter Site home page Giter Site logo

Responsive about xzoom HOT 5 CLOSED

payalord avatar payalord commented on July 30, 2024
Responsive

from xzoom.

Comments (5)

payalord avatar payalord commented on July 30, 2024

Ok, now let assume per different screen size you have different layout for responsive output of your design. Right now there is no native options available to set this quickly. But to achieve this manual control per screen size of setting the type of zoom, we can try next JS code with xZoom API:

(function ($) {
    $(document).ready(function() {
        function manual_responsive(xzoom) {
            var width = $(window).width();
            if (width < 500) {
                xzoom.options.position = "fullscreen"
            } else if (width < 700) {
                xzoom.options.position = "bottom"
            } else if(width < 960) {
                xzoom.options.position = "left"
            } else {
                xzoom.options.position = "right"
            }
        }

        var instance = $('.xzoom, .xzoom-gallery').xzoom({adaptive: false});

        manual_responsive(instance);
        $(window).resize(function() {
            manual_responsive(instance);
        });
    });
})(jQuery);

Here, I have created new function manual_responsive in which I used if condition scheme per every width I need, to have a manual control on it. Make sure the order of width is in ascendant order. And the last one of them is default.

P.S. Make sure that adaptive option is set to false, when you taking manual control over responsive like this one.

from xzoom.

psweeting1 avatar psweeting1 commented on July 30, 2024

Outstanding, thank you very much for your time and help, your plugin is amazing. This works and has fixed my problem, I would of never worked that out.

(function ($) {
    $(document).ready(function() {
        function manual_responsive(xzoom) {
            var width = $(window).width();
            if (width < 992) {
                xzoom.options.position = "inside"
            } else if(width < 1200) {
                xzoom.options.position = "right";
                xzoom.options.Xoffset = 5;
                xzoom.options.zoomWidth = 655;
                xzoom.options.zoomHeight = 420;
            } else {
                xzoom.options.position = "right";
                xzoom.options.Xoffset = 100;
                xzoom.options.zoomWidth = 667;
                xzoom.options.zoomHeight = 410;
            }
        }

        var instance = $('#main_image, .xzoom-gallery').xzoom({
            tint: '#333',
            adaptive: false,
            smoothZoomMove: 0,
            smoothLensMove: 0,
            smoothScale: 0,
            hover: true,
            defaultScale: 0
        });

        manual_responsive(instance);
        $(window).resize(function() {
            manual_responsive(instance);
        });
    });
})(jQuery);

This is my code, I know I could of simplify the syntax for xzoom.options to an $.extend but for easy reading for anyone else new to jQuery, I hope this helps.

from xzoom.

psweeting1 avatar psweeting1 commented on July 30, 2024

If xZoom is not being used on a webpage it crashes my other Javascript and jQuery that I'm using.

Uncaught TypeError: Cannot set property 'position' of undefined

This error always appears. I'm still using the same script from my previous comment.

from xzoom.

psweeting1 avatar psweeting1 commented on July 30, 2024

Sorry I fixed it, I wrapped it in an if statement.

if($('#main_image').length === 1) {
//run the script
}

from xzoom.

payalord avatar payalord commented on July 30, 2024

No problem, thanks for sharing your solution 👍

from xzoom.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.