Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for scroll methods #373

Open
juandavm opened this issue Apr 24, 2021 · 8 comments
Open

Support for scroll methods #373

juandavm opened this issue Apr 24, 2021 · 8 comments

Comments

@juandavm
Copy link

Please, support the jQuery scrollTop method
https://api.jquery.com/scrolltop/

It's a widely used method of jQuery

@fabiospampinato
Copy link
Owner

Happy to add these, if somebody can manage to squeeze enough bytes out of the bundle, I think we are currently nearly at 6kb min+giz, I don't want to exceed that.

@fabiospampinato fabiospampinato changed the title Please, support the scrollTop method Support for scroll methods May 4, 2021
@vovayatsyuk
Copy link
Contributor

vovayatsyuk commented May 12, 2021

@juandavm, meanwhile, I recommend creating cash-extends.js file with all new methods you need. Here is a scrollTop implementation:

$.fn.scrollTop = function (val) {
    var el = this.get(0);

    if (val === undefined) {
        return el ? el.scrollTop : null;
    }

    if (el) {
        el.scrollTop = val;
    }

    return this;
};

@fabiospampinato
Copy link
Owner

@vovayatsyuk Actually that might be buggy because this.get (0) can return undefined.

@vovayatsyuk
Copy link
Contributor

vovayatsyuk commented May 12, 2021

Ah, yes.. Fixed now. I hope :)

Thank you.

p.s. Fixed one more time.🤫

@cyfung1031
Copy link

cyfung1031 commented Jul 20, 2021

Cash has removed the shortcuts like ".scroll" ".click" (basically it is $(...).on("scroll", ...) )
Similarly, you shall use $(...).prop("scrollTop", ... ) instead.

$.fn.scrollTop = function (val) {

    if (val === undefined) {
        return this.prop('scrollTop');
    }

    return this.prop('scrollTop', val);

};

@AliN11
Copy link

AliN11 commented Jan 14, 2022

@juandavm, meanwhile, I recommend creating cash-extends.js file with all new methods you need. Here is a scrollTop implementation:

$.fn.scrollTop = function (val) {
    var el = this.get(0);

    if (val === undefined) {
        return el ? el.scrollTop : null;
    }

    if (el) {
        el.scrollTop = val;
    }

    return this;
};

Replaced el.scrollTop with el.pageYOffset and everything works fine:

$.fn.scrollTop = function (val) {
    var el = this.get(0);

    if (val === undefined) {
        return el ? el.pageYOffset : null;
    }

    if (el) {
        el.pageYOffset = val;
    }

    return this;
}

@omidgfx
Copy link

omidgfx commented Apr 25, 2023

@juandavm, meanwhile, I recommend creating cash-extends.js file with all new methods you need. Here is a scrollTop implementation:

$.fn.scrollTop = function (val) {
    var el = this.get(0);

    if (val === undefined) {
        return el ? el.scrollTop : null;
    }

    if (el) {
        el.scrollTop = val;
    }

    return this;
};

Replaced el.scrollTop with el.pageYOffset and everything works fine:

$.fn.scrollTop = function (val) {
    var el = this.get(0);

    if (val === undefined) {
        return el ? el.pageYOffset : null;
    }

    if (el) {
        el.pageYOffset = val;
    }

    return this;
}

But it's not working!

@cyfung1031
Copy link

cyfung1031 commented Sep 27, 2023

Happy to add these, if somebody can manage to squeeze enough bytes out of the bundle, I think we are currently nearly at 6kb min+giz, I don't want to exceed that.

Can we have partial build option so that there will be "polyfill" for .click, .scroll, etc which are excluded by default, but user can do the partial build to add @require events/click.ts (the ts file is provided in this repo)
This can help users to do migration easier and they might not care about the file size increment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants