Media queries are probably the best solution for providing alternative styles for mobile users. Unfortunately there is no media attribute for the <script> element to proceed similarly in the case of page logic.
You can, however, provide a script loader which will load desired .js file depending on the style sheet selected by the browser on the basis of your media query. I don't know how to do this in a direct, elegant way but there is a nice hack for that. You have to "mark" each .css with a unique declaration (dummy, unimportant or different by design) and check it from within JS after the page has loaded to determine which style sheet has been applied by the browser.
The CSS could look like this:
@media handheld, screen and (max-width:1023px) {
body {margin-top: 1px}
}
@media screen and (min-width:1024px) {
body {margin-top: 0px}
}
/* These would be separate .css files in a real example */
And the accompanying JS as follows:
window.setTimeout('wait()', 10);
function wait() {
if (!document.body)
window.setTimeout('wait()', 100)
else
onLoad();
}
function onLoad() {
var load = document.createElement('script');
var head = document.getElementsByTagName('head')[0];
var body = document.getElementsByTagName('body')[0];
var mark = window.getComputedStyle(body).getPropertyValue('margin-top');
switch (mark) {
case '0px':
load.setAttribute('src', 'handheld.js');
break;
case '1px':
load.setAttribute('src', 'screen.js');
break;
default:
load.setAttribute('src', 'somethingelse.js');
}
head.appendChild(load);
}