From 039249759fba99afb655f1d636e14cdb1c2cbe36 Mon Sep 17 00:00:00 2001
From: Eike Send
Resize your browser window now and watch events in the box below.
-
- 1024 480 320 Changing breakpoint: old breakpoint = ' + info.oldBP + ", new breakpoint: " + info.newBP);
- $('body').removeClass("breakpoint-320 breakpoint-480 breakpoint-768 breakpoint-1024");
+ $('body').removeClass("breakpoint-0 breakpoint-320 breakpoint-480 breakpoint-768 breakpoint-1024");
$('body').addClass("breakpoint-"+info.newBP);
});
- $(window).breakpoints([320, 480, 768, 1024]);
+ $(window).breakpoints([0, 320, 480, 768, 1024]);
});
@@ -27,6 +27,7 @@
.breakpoint-768 #status p.breakpoint768 { color: #000; font-weight:bold; background: #F0F0F0;}
.breakpoint-480 #status p.breakpoint480 { color: #000; font-weight:bold; background: #F0F0F0; }
.breakpoint-320 #status p.breakpoint320 { color: #000; font-weight:bold; background: #F0F0F0; }
+ .breakpoint-0 #status p.breakpoint0 { color: #000; font-weight:bold; background: #F0F0F0; }
768 480 320 0
- Resize your browser window now and watch events in the box below.
- 1024 768 480 320 0 Media queries for JavaScript
+ Breakpoints.js is a javascript library which lets you bind to resize
+ events on an advanced level. You provide an array of screen widths
+ and a callback function which is called whenever one of these
+ breakpoints is crossed.
+
+ If the browser is resized by using the maximize button of the browser, all
+ the breakpoints that are in between are triggered as separate events.
+
+ breakpoints.js makes the most sense when you do responsive design and you
+ would like to reorder elements in the DOM for certain screen sizes and
+ you can't do it with regular media queries. For example move selected
+ items into the sidebar which are part of the regular page on mobile
+ devices.
+
+
+ Resize your browser window to see new log entries below or changes to the active breakpoint above.
+
+
- Breakpoints.js is a javascript library which lets you bind to resize
- events on an advanced level. You provide an array of screen widths
- and a callback function which is called whenever one of these
- breakpoints is crossed.
-
- If the browser is resized by using the maximize button of the browser, all
- the breakpoints that are in between are triggered as separate events.
-
- breakpoints.js makes the most sense when you do responsive design and you
- would like to reorder elements in the DOM for certain screen sizes and
- you can't do it with regular media queries. For example move selected
- items into the sidebar which are part of the regular page on mobile
- devices.
-
+ Breakpoints.js is a javascript library which lets you bind to resize
+ events on an advanced level. You provide an array of screen widths
+ and a callback function which is called whenever one of these
+ breakpoints is crossed.
+
+ If the browser is resized by using the maximize button of the browser, all
+ the breakpoints that are in between are triggered as separate events.
+
+ breakpoints.js makes the most sense when you do responsive design and you
+ would like to reorder elements in the DOM for certain screen sizes and
+ you can't do it with regular media queries. For example move selected
+ items into the sidebar which are part of the regular page on mobile
+ devices.
+ Demo
-
Active Breakpoints
Active Breakpoints
Event Log:
-
Active Breakpoints
Event Log:
From cc52b662aad6da12aca52ddff4cac0fac5fbb4da Mon Sep 17 00:00:00 2001
From: Eike Send Demo
- Active Breakpoints
- Event Log:
- breakpoints.js
+ Active Breakpoint:
+ Responsive JavaScript
+ Usage
+
+ <script type="text/javascript" src="breakpoints.js"></script>
+ <script type="text/javascript">
+ breakpoints([0, 160, 320, 480, 768, 1024], function(oldPoint, newPoint) {
+ console.log(oldPoint, newPoint);
+ });
+ <script>
+
+ Demo
+ Event Log:
+
+
From bcef1a6909d88913cf2e6e6a672575b9d137d507 Mon Sep 17 00:00:00 2001
From: Eike Send Active Breakpoint:
768
1024
- Responsive JavaScript
- Responsive JavaScript
+ Usage
<script type="text/javascript" src="breakpoints.js"></script>
@@ -59,11 +65,13 @@ Demo
Resize your browser window to see new log entries below or changes to the active breakpoint above.
diff --git a/moveElements.js b/moveElements.js
new file mode 100644
index 0000000..0c2a13f
--- /dev/null
+++ b/moveElements.js
@@ -0,0 +1,51 @@
+(function(){
+ // Adapted from Dustin Diaz Code:
+ function getElementsByClass(searchClass,node,tag) {
+ if ( node == null ) node = document;
+ if ( tag == null ) tag = '*';
+ if ( document.getElementsByClassName ) {
+ return node.getElementsByClassName(searchClass);
+ } else {
+ var els = node.getElementsByTagName(tag);
+ var classElements = new Array();
+ var elsLen = els.length;
+ var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
+ for (i = 0; i < elsLen; i++) {
+ if ( pattern.test(els[i].className) ) {
+ classElements.push(els[i]);
+ }
+ }
+ return classElements;
+ }
+ }
+
+ moveElements = function(breakPoint, destinationElement, sourceClassName, sourceWrapperElement, sourceTagName) {
+ var elements = getElementsByClass(sourceClassName, sourceWrapperElement, sourceTagName);
+ var placeHolders = [];
+ breakpoints.bind(function(oldPoint, newPoint) {
+ if (oldPoint < newPoint && newPoint == breakPoint) {
+ for (var i = elements.length-1; i >= 0; i--) {
+ var parentEl = elements[i].parentElement;
+ if (placeHolders[i] === undefined) {
+ placeHolders[i] = document.createElement("span");
+ parentEl.insertBefore(placeHolders[i], elements[i]);
+ }
+ var el = parentEl.removeChild(elements[i]);
+ destinationElement.insertBefore(el, destinationElement.firstChild);
+ }
+ }
+ if (oldPoint > newPoint && oldPoint == breakPoint) {
+ var l = elements.length-1;
+ var removedEls = [];
+ for (var i = l; i >= 0; i--) {
+ var parentEl = elements[i].parentElement;
+ removedEls[i] = parentEl.removeChild(elements[i]);
+ }
+ for (var i = l; i >= 0; i--) {
+ placeHolders[i].parentElement.insertBefore(removedEls[i], placeHolders[i]);
+ }
+ }
+ });
+ }
+
+})();
From 3e12716b7f98380115f01637db756026fe4d3882 Mon Sep 17 00:00:00 2001
From: Eike Send
- <script type="text/javascript" src="breakpoints.js"></script>
+ <script type="text/javascript" src="breakpoints.min.js"></script>
+ <script type="text/javascript" src="relocate.min.js"></script>
<script type="text/javascript">
breakpoints([0, 160, 320, 480, 768, 1024], function(oldPoint, newPoint) {
console.log(oldPoint, newPoint);
});
+ relocate(480, document.getElementById("target"), "movethis");
<script>
diff --git a/moveElements.js b/relocate.js
similarity index 93%
rename from moveElements.js
rename to relocate.js
index 0c2a13f..3493123 100644
--- a/moveElements.js
+++ b/relocate.js
@@ -19,7 +19,7 @@
}
}
- moveElements = function(breakPoint, destinationElement, sourceClassName, sourceWrapperElement, sourceTagName) {
+ relocate = function(breakPoint, destinationElement, sourceClassName, sourceWrapperElement, sourceTagName) {
var elements = getElementsByClass(sourceClassName, sourceWrapperElement, sourceTagName);
var placeHolders = [];
breakpoints.bind(function(oldPoint, newPoint) {
diff --git a/relocate.min.js b/relocate.min.js
new file mode 100644
index 0000000..800c106
--- /dev/null
+++ b/relocate.min.js
@@ -0,0 +1 @@
+(function(){function a(a,b,c){b==null&&(b=document),c==null&&(c="*");if(document.getElementsByClassName)return b.getElementsByClassName(a);var d=b.getElementsByTagName(c),e=new Array,f=d.length,g=new RegExp("(^|\\s)"+a+"(\\s|$)");for(i=0;i