Last active
December 22, 2015 15:38
-
-
Save torounit/6493312 to your computer and use it in GitHub Desktop.
ウィンドウサイズで、CSSを切り替えるのを実装するためのjQueryプラグイン。media queriesを使うほどでもない場合用。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do ($=jQuery) -> | |
$.fn.semiMediaQuery = (breakpoints) -> | |
@init = (breakpoints) => | |
@breakpoints = breakpoints | |
@getElements() | |
@delegateEvents() | |
@setWidthClass() | |
@getElements = () => | |
@$window = $(window) | |
@$document = $(document) | |
@delegateEvents = () => | |
@$window.on "load", @setWidthClass.bind(@) | |
@$window.on "resize", @setWidthClass.bind(@) | |
@getWidth = () => | |
@width(); | |
@setWidthClass = () => | |
width = @getWidth() | |
for i, point of @breakpoints | |
if point < width | |
@.addClass( "wid-gt-"+point ) | |
@.removeClass( "wid-lte-"+point ) | |
else | |
@.removeClass( "wid-gt-"+point ) | |
@.addClass( "wid-lte-"+point ) | |
@init(breakpoints); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do ($=jQuery) -> | |
$ -> | |
$("html").semiMediaQuery(Array( 960, 1024, 1200 )); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html class="wid-lte-1200 wid-lte-960 wid-lte-1024"></html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment