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

Disable matchHeight on Mobile #99

Open
kaspar-allenbach opened this issue Dec 22, 2015 · 7 comments
Open

Disable matchHeight on Mobile #99

kaspar-allenbach opened this issue Dec 22, 2015 · 7 comments
Labels

Comments

@kaspar-allenbach
Copy link

I want to disable certain matchHeigh elements on mobile devices.

So I wrote this:

if ($(window).width() < 768) {
    $('.noMatch').matchHeight({ remove: true });
  }

The idea would be that elements with .noMatch wouldn't fire on devices with less than 768px.

But it doesn't work. How would I have to write this properly?

@liabru
Copy link
Owner

liabru commented Dec 28, 2015

I think this should work, could there be a problem somewhere else in your code?
You could also try only selecting the required elements, so you wouldn't need to use remove.

@Bobz-zg
Copy link

Bobz-zg commented Jan 30, 2016

I would +1 for an option to define attribute min/max eg:
<div class="item" data-mh="group-name" data-mh-min="768"> .. </div>

@patrickfweston
Copy link

I used the following function that I attached to the jQuery object:

(function ($) {

    // Add a function to jQuery that lets us add/remove the matchHeight script
    // depending on a breakpoint.
    jQuery.fn.equalHeightResponsive = function(breakpoint) {
        if ($(window).width() < breakpoint) {
            // If the matchHeight script is active, remove it from this set of elements
            if (this.data('matchHeight') === 'true') {
                this.data('matchHeight', 'false');
                this.matchHeight({ remove: true });
            }
        } else {
            // If the matchHeight script hasn't been added, add it in
            if (this.data('matchHeight') === 'false' || typeof this.data('matchHeight') === "undefined") {
                this.data('matchHeight', 'true');
                this.matchHeight();
            }
        }
    }

})(jQuery);

Then, you can call it on your items on page load and window resize:

$(document).ready(function() {
        $('.card').equalHeightResponsive('900');
    });

$(window).resize(function() {
    $('.card').equalHeightResponsive('900');
});

I used a data attribute value as a flag to see if the script had already been added/removed. This way, you're not attaching a bunch of handlers to your elements and running the matchHeight script a bunch of times. There's probably a better solution, but this is working for me.

@liabru
Copy link
Owner

liabru commented Mar 10, 2016

I think there's a pull request related to this see #65, does that help anybody?

@aravikanti
Copy link

@liabru +1 for the merge.

@kyds3k
Copy link

kyds3k commented Mar 16, 2017

Just to add my 2 cents in, I simply disabled the inline CSS using a media query and this technique:

https://css-tricks.com/override-inline-styles-with-css/

Took me no time and worked a treat!

@ezetojo
Copy link

ezetojo commented Nov 13, 2017

Working solution for bootstrap 3. Based on @kyds3k answer.

@media (max-width:992px) {
    .match[style] {
        height: auto !important;
    }
}

I used it for xs and sm resolutions. If you want to apply it only on xs change media query to 768px.

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

No branches or pull requests

7 participants