Giter Club home page Giter Club logo

minwidth-relocate's Introduction

Read the blog post which describes these tools with a nice demo:

http://edenspiekermann.com/blog/posts/responsive-javascript-helpers

minwidth.js

minwidth.js is a javascript library that helps you create fantastic mobile first websites. You provide a width at which your functions are called.

Several use-cases have occured so many times that it made sense to sort this problem out properly. One thing that happened to us often when designing mobile first web-sites is that some elements need to be in a different place in the DOM on wider screens. Another problem was loading certain scripts only desktop screens.

minwidth.js lets you bind to resize events on an advanced level. You provide a screen width and a callback function which is called whenever this width is crossed. You may provide another function which is called when the window is resized back below that width.

minwidth(600, function() {
  doSomethingLikeLoadFacebook();
});

interface

minwidth(width, forwardCallback, backwardCallback, desktopFirst);

width specifies the breakpoint at which the callbacks should be fired.

forwardCallback is the function that is called if the screen is wider than than the width.

backwardCallback (optional) is the function that is called if the screen becomes smaller than than the width.

desktopFirst (optional) is a boolean which lets you specify that you want to work in a desktop-first fashion. If true, the backwardCallback is then called if the screen is initially smaller than the width, the forwardCallback will only be called if the screen becomes wider than the width, in this case you can pass false as an argument to the forwardCallback.

relocate.js

relocate.js lets you move elements in the DOM from their original place to another when you can't do that desktop design with CSS media queries.

For example move selected items into the sidebar which are mixed into the regular page on mobile devices.

var elements = document.getElementsByClassName("movethis");
var sidebar = document.getElementById("sidebar");
relocate(480, elements, sidebar);

Note: IE8 and less don't have getElementsByClassName, you can use jQuery or this getElementsByClassName polyfill

interface

relocate(width, elements, destinationElement, desktopFirst);

width specifies the breakpoint at which the elements should be relocated.

elements can be a single HTMLElement or an Array of HTMLElements, a NodeList or a HTMLCollection. They will be relocated.

destinationElement is the HTMLElement into which the elements will be relocated.

desktopFirst (optional) is a boolean which lets you specify that you want to work in a desktop-first fashion. If true, the elements will only be relocated if the screen is initially smaller or becomes smaller than the given width.

Minification

rm minwidth-relocate.min.js && cat *.js | uglifyjs -nc > minwidth-relocate.min.js

License

The code is dual-licensed under the GNU General Public License Version 2 (GPLv2) and the MIT License.

minwidth-relocate's People

Contributors

eikes avatar mguth avatar ore4444 avatar

Watchers

La petite machine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.