Giter Site home page Giter Site logo

responsiveloader's Introduction

#Responsive Loader A javascript module to conditionally load any DOM elements based on media query.

##What? Load mobile-friendly components on small devices, and a more robust or heavier-load component on desktops. Use CSS to hide DOM elements already loaded, but to only load assets and content when required you need to add some javascript.

##How? Include the module and use script tags to markup your conditional content in HTML, set the class of the script element (default 'responsive-loader') add a data-target atttribute to set the id of the target HTML element, and a data-media-query attribute to set the media query condition.

For example:

<script src="/js/responsiveLoader.min.js"></script>
<script>ResponsiveLoader.run();</script>
<div id="example-1">
	<script type="text/conditional-html" class="responsive-loader" data-target="example-1" data-media-query='(min-width:30em)'>
		<h1>Text at min-width:30em</h1>
	</script>
	<noscript><h1>Text at min-width:30em</h1></noscript>
</div>
<div id="example-2">
	<script type="text/conditional-html" class="responsive-loader" data-target="example-1" data-media-query='(min-width:48em)'>
		<h1>Text at min-width:48em</h1>
	</script>
	<noscript><h1>Text at min-width:48em</h1></noscript>
</div>

##Options @className type: String default: 'responsive-loader' description: className that identifies content to be condtionally loaded

@callback type: function default: false description: Function called when content is loaded

##Requirements No dependencies. Browsers without matchMedia do not cut the mustard and all conditional content is loaded. THe module requires addEventListener, removeEventLister and matchMedia, if not available they must be polyfilled for use with non-modern browsers.

##Roadmap Add data-callback support for individual callbacks on conditional content

responsiveloader's People

Contributors

mjbp avatar

Watchers

James Cloos avatar  avatar

Forkers

nsswebservices

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.