0

With twitter-bootstrap it is possible to achieve responsive behavior by applying css to markup like visible-lg visible-md visible-sm responsive-utilities for example.

But how about if i want to apply specific JavaScript for specific resolution.

lets say I have javascript like that:

$('.mainHeader').affix({
        offset: {
            top: 585
        }
    }); 

I want value top make dynamic based on current resolution. lets say if current resolution visible-lg I want top: 20, if current resolution visible-md I want top: 300 etc..

Is there any clever way to achieve that with twitter-bootstrap?

2
  • Consider using enquire.js. Commented Dec 23, 2013 at 0:47
  • This might be helpful window width else if Commented Dec 23, 2013 at 1:06

1 Answer 1

0

You can use matchMedia API to detect certain screen width, so you can do this

if ( window.matchMedia('(min-width: 768px)').matches ) {
    $(element).affix({
        offset: {
            top: 585
        }
    });
} else if ( window.matchMedia('(min-width: 992px)').matches ) {
    // change the affix offset
}

Need to know that matchMedia API only supported on IE10+ reference. The other alternative you can Modernizr mq() function. Read the documentation here to learn more.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.