Given I have this snippet
<div class="container">
<div class="row">
<div id="left" class="col-xs-5 col-sm-5">
How are you?
</div>
<div id="right" class="col-xs-7 col-sm-7">
Thanks, I'm fine.
</div>
</div>
</div>
If open on browser it should display
How are you? Thanks, I'm fine.
When browser is reduced to less than 768px I want the above snippet to yield
Thanks, I'm fine.
How are you?
I am using the following javascript to detect when viewport width of browser is <=767.
/*
@Leo
Obtained from:
http://stackoverflow.com/questions/1766861/find-the-exact-height-and-width-of-the-viewport-in-a-cross-browser-way-no-proto
*/
var getviewport = function(){
var viewPortWidth;
var viewPortHeight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined') {
viewPortWidth = window.innerWidth,
viewPortHeight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0) {
viewPortWidth = document.documentElement.clientWidth,
viewPortHeight = document.documentElement.clientHeight
}
// older versions of IE
else {
viewPortWidth = document.getElementsByTagName('body')[0].clientWidth,
viewPortHeight = document.getElementsByTagName('body')[0].clientHeight
}
return [viewPortWidth, viewPortHeight];
};
var adjust = function(){
var width = getviewport()[0];
if(width<=767){
$("#left").addClass("col-xs-push-7");
$("#right").addClass("col-xs-pull-5");
}
else{
$("#left").removeClass("col-xs-push-7");
$("#right").removeClass("col-xs-pull-5"); }
};
adjust();
$(window).resize(adjust);
So when the viewport width is <=767. I try to order the statement
"How are you? Thanks, I'm fine." to "Thanks, I'm fine. How are you?
By adding corresponding xs-push-* and xs-pull-* I was able to achieve the above ordering to "Thanks, I'm fine. How are you?"
However, I feel something can be further done to break the statement to
Thanks, I'm fine.
How are you?
I will be glad if someone can offer help.