-
Notifications
You must be signed in to change notification settings - Fork 0
Home
yura-x edited this page Mar 31, 2015
·
5 revisions
This plugin adds CSS classes depending from element width Pass your breakpoints to plugin in pixels and it will automatically add following CSS classes to your elements:
width-lt-xxx
width-gt-xxx
where 'xxx' is your breakpoint value
<div style="width: 350px">
<h3>h3 tag 350px width</h3>
</div>
<div style="width: 450px">
<h3>h3 tag 450px width</h3>
</div>
<div style="width: 550px">
<h3>h3 tag 550px width</h3>
</div>
<div style="width: 650px">
<h3>h3 tag 650px width</h3>
</div>
<script src="jquery-1.11.2.min.js"></script>
<script src="jquery.addwidthclass.js"></script>
jQuery(document).ready(function(){
jQuery('h3').addWidthClass({
breakpoints: [400, 500, 600]
});
});
If you done right, the result will be:
<div style="width: 350px">
<h3 class="width-lt-600 width-lt-500 width-lt-400">h3 tag 350px width</h3>
</div>
<div style="width: 450px">
<h3 class="width-lt-600 width-lt-500 width-gt-400">h3 tag 450px width</h3>
</div>
<div style="width: 550px">
<h3 class="width-lt-600 width-gt-500 width-gt-400">h3 tag 550px width</h3>
</div>
<div style="width: 650px">
<h3 class="width-gt-600 width-gt-500 width-gt-400">h3 tag 650px width</h3>
</div>
h3 {
background: #eee;
color: #111;
}
h3.width-gt-400{
background: #ccc;
color: #333;
}
h3.width-gt-500{
background: #111;
color: #eee;
}
h3.width-gt-600{
background: #aaa;
color: #fff;
}