Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:48:43+00:00 2026-06-05T14:48:43+00:00

I am using Paul Hayes’ CSS Transitions Media Query script and can not figure

  • 0

I am using Paul Hayes’ CSS Transitions Media Query script and can not figure out how to do a simple if/else.

Here is what I am going after:

mql('all and (max-width: 959px)', change);
mql('all and (min-width: 960px)', change);

function change(mql) {
    if(max-width: 959px) {
        console.log("Do this");
    } else {
        console.log("Do that");
    }
}

Here is mql / paul’s script:

mql = (function(doc, undefined) {

    var docElem = doc.documentElement,
        refNode = docElem.firstElementChild || docElem.firstChild,
        idCounter = 0;
        if(!doc.getElementById('mq-style')) {
          style = doc.createElement('style');
          style.id = 'mq-style';
          style.textContent = '.mq { -webkit-transition: width 0.001ms; -moz-transition: width 0.001ms; -o-transition: width 0.001ms; -ms-transition: width 0.001ms; width: 0; position: absolute; top: -100em; }\n';
          docElem.insertBefore(style, refNode);          
        }

     var transitionEnds = Array('transitionend','webkitTransitionEnd','oTransitionEnd','msTransitionEnd');

     for(var i in transitionEnds) { 
    if ('on'+ transitionEnds[i].toLowerCase() in window)  transitionEnd = transitionEnds[i];
     }  

    return function(q, cb) {

        var id = 'mql-' + idCounter++,
            callback = function() {
                // perform test and send results to callback
                cb({
                    matches: (div.offsetWidth == 42),
                    media: q
                });
            },
            div = doc.createElement('div');

        div.className = 'mq'; // mq class in CSS declares width: 0 and transition on width of duration 0.001ms
        div.id = id;
        style.textContent += '@media ' + q + ' { #' + div.id + ' { width: 42px; } }\n';        

        // add transition event listener
        div.addEventListener(transitionEnd, callback, false); 

        docElem.insertBefore(div, refNode);

        // original polyfill removes element, we need to keep element for transitions to continue and events to fire.

        return {
            matches: div.offsetWidth == 42,
            media: q
        };
    };

})(document);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:48:45+00:00Added an answer on June 5, 2026 at 2:48 pm

    The only way I can se this be done with the information provided in the change function is this:

    mql('all and (max-width: 959px)', change);
    mql('all and (min-width: 960px)', change);
    
    function change(mql) {
        if(mql.media.indexOf('max-width: 959px') !== -1 && mql.matches) {
            console.log("Do this");
        } else {
            console.log("Do that");
        }
    }
    

    But I have to say that it doesn’t feel that good… I would consider two separate callbacks one for each media-query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the css modal box described by Paul R.Hayes here - http://www.paulrhayes.com/experiments/modal/
Can it possible to disconnect ongoing call using the app.I have get out the
Using WebViewBrush I can render web page content (it's screen shot) to e.g. Rectangle
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
Using Yii, I want to delete all the rows that are not from today.
I am using JavaScript. I have var myobj = { "one": { "name": "paul",
I'm trying to learn assembly using Dr Paul Carter's pcasm book: http://www.drpaulcarter.com/pcasm/ The author
I'm using the excellent Magellan navigation framework from Paul Stovell . When you have
I'm trying to learn assembly using NASM, the pcasm-book.pdf from Dr Paul Carter -
Is there a good tutorial for Creating a database using msbuild ? jean paul

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.