Code Monkey home page Code Monkey logo

appendaround's Introduction

AppendAround

A pattern for responsive markup

  • [c]2012, @scottjehl, Filament Group, Inc. MIT/GPL

how-to

1. Insert potential element containers throughout the DOM
2. give each container a data-set attribute with a value that matches all other containers' values
3. Place your appendAround content in one of the potential containers
4. Configure your CSS to only display one potential container at a time (and display others depending on @media conditions in your CSS)
4. Call appendAround() on that element when the DOM is ready, and it'll keep itself in a visibile container at all times

Sample markup

  <!-- potential container for appendAround -->
  <div class="foo" data-set="foobarbaz"></div>

  <ul>
   <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
   <li>Aliquam tincidunt mauris eu risus.</li>
   <li>Vestibulum auctor dapibus neque.</li>
</ul>

  <!-- potential container for appendAround -->
  <div class="bar" data-set="foobarbaz"></div>

  <ul>
   <li>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</li>
   <li>Aliquam tincidunt mauris eu risus.</li>
   <li>Vestibulum auctor dapibus neque.</li>
</ul>


  <!-- initial container for appendAround -->
  <div class="baz" data-set="foobarbaz">

    <p class="sample">Sample appendAround Element</p>

  </div>

Sample CSS

/* the sample appendaround element */
.sample {
	padding: 1em;
	background: tan;
}

.baz {
	display: block;
}
.foo,
.bar {
	display: none; 
}

@media (min-width: 30em){
	.bar {
	  display: block;
	}
	.foo, .baz {
	  display: none; 
	}
}

@media (min-width: 50em){
	div.foo {
	  display: block;
	}
	div.bar, div.baz {
	  display: none; 
	}
}

Sample JavaScript call

$( ".sample" ).appendAround();

appendaround's People

Contributors

scottjehl avatar

Watchers

 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.