jsor / jcarousel

Riding carousels with jQuery.
https://sorgalla.com/jcarousel/
MIT License
1.99k stars 736 forks source link

support for css scaling #632

Closed mmjr closed 10 years ago

mmjr commented 10 years ago

It would be great if you could support scale of container.

Right now the scale works but the scrolling moves several slides each time instead of one.

Thanks

jsor commented 10 years ago

Could you setup an example on http://jsfiddle.net?

mmjr commented 10 years ago

Sorry, should of done that in the first place.

Cats an all: http://jsfiddle.net/TYUu9/

Thanks

mmjr commented 10 years ago

Just a quick explanation: the div with class jcarousel has a css transform of: -webkit-transform: matrix(2, 0, 0, 2, 0, 0);

what I have been able to see is that the calculation of the left property on the ul when sliding is not taking in account the scale factor.

mmjr commented 10 years ago

Digging in the Jcarousel code, under the _scroll function. I have divided the pos variable which sets the left property by the scale factor. This seems to fix the issue. However, when reloading the carousel(I am loading images dynamically) it seems to brake ths navigation again.

mmjr commented 10 years ago

_scroll: function(item, animate, callback) { if (this.animating) { if ($.isFunction(callback)) { callback.call(this, false); }

            return this;
        }

        if (typeof item !== 'object') {
            item = this.items().eq(item);
        } else if (typeof item.jquery === 'undefined') {
            item = $(item);
        }

        if (item.length === 0) {
            if ($.isFunction(callback)) {
                callback.call(this, false);
            }

            return this;
        }

        this.inTail = false;

        this._prepare(item);

        var pos     = this._position(item),
            currPos = this.list().position()[this.lt];

        if (pos === currPos) {
            if ($.isFunction(callback)) {
                callback.call(this, false);
            }

            return this;
        }

        var properties = {};

        var matrixRegex = /matrix\((-?\d*\.?\d+),\s*0,\s*0,\s*(-?\d*\.?\d+),\s*0,\s*0\)/,
            matches = $(this.element()).css('-webkit-transform').match(matrixRegex) || $($(this.element().parent())).css('-webkit-transform').match(matrixRegex) || [];

         pos *= (1/matches[1]);

        properties[this.lt] = pos + 'px';

        this._animate(properties, animate, callback);

        return this;
    },
jsor commented 10 years ago

I thought you were talking about the browser zoom. Not sure it's worth to fully support this since i'd consider this an edge case. I will keep it on my todo-list and will dig into this if i find time.

mmjr commented 10 years ago

Ok, sorry to hear that. we need support for all css transitions and transforms.

Ill have a go at fixing it myself...

mmjr commented 10 years ago

Thanks for responding though