Skip to main content
本文に 664 文字追加
ソース リンク
BLUEPIXY
  • 6,907
  • 1
  • 21
  • 34

<!doctype html>

jQueryFrameworks

AllCSSJavaScriptPHPRubyPythonScalaBootstrap

Ruby on Rails

Phalcon

React

Play

Aurelia

Django

Material UI

Laravel

$(function(){$(".select").on('change',function(){var v=$(this).val();$('ul.list li').toggle(v=="All").filter('[data-category-type='+v+']').show();}).trigger('change');});

.clearfix:after {
display: block;
clear: both;
content: '';
}
.wrapper {
padding: 20px;
}
.contents {
margin: 0 auto;
width: 300px;
}
.title {
padding: 10px;
font-size: 24px;
font-weight: bold;
text-align: center;
background-color: #fff;
}
.select-wrapper {
margin: 10px 0;
text-align: right;
}
.select {
padding: 10px;
width: 100px;
font-size: 14px;
color: #fff;
border: none;
border-radius: 0;
background-color: darkcyan;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
cursor: pointer;
-webkit-appearance: none;
}
.list > li {
border-top: 1px #eee solid;
}
.article {
position: relative;
display: table;
padding: 10px;
width: 100%;
background-color: #fff;
table-layout: fixed;
}
.article-icon {
display: table-cell;
width: 50px;
height: 50px;
background-size: cover;
}
.article-icon.is-bootstrap { background-image: url(../img/bootstrap.png); }
.article-icon.is-material-ui { background-image: url(../img/material-ui.png); }
.article-icon.is-react { background-image: url(../img/react.png); }
.article-icon.is-aurelia { background-image: url(../img/aurelia.png); }
.article-icon.is-ruby-on-rails { background-image: url(../img/ruby-on-rails.png); }
.article-icon.is-laravel { background-image: url(../img/laravel.png); }
.article-icon.is-phalcon { background-image: url(../img/phalcon.png); }
.article-icon.is-django { background-image: url(../img/django.png); }
.article-icon.is-play { background-image: url(../img/play.png); }
.article-name {
display: table-cell;
padding-left: 20px;
width: 100%;
font-size: 16px;
font-weight: bold;
vertical-align: middle;
}

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>jQuery</title>
<link rel="stylesheet" href="../../common/css/reset.css">
<link rel="stylesheet" href="../../common/css/base.css">
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div class="wrapper">
  <div class="contents">
    <p class="title">Frameworks</p>
    <div class="select-wrapper">
      <select class="select">
        <option value="all">All</option>
        <option value="css">CSS</option>
        <option value="javascript">JavaScript</option>
        <option value="php">PHP</option>
        <option value="ruby">Ruby</option>
        <option value="python">Python</option>
        <option value="scala">Scala</option>
      </select>
    </div>
    <ul class="list">
      <li data-category-type="css">
        <a href="http://getbootstrap.com/" class="article">
          <i class="article-icon is-bootstrap"></i>
          <p class="article-name">Bootstrap</p>
        </a>
      </li>
      <li data-category-type="ruby">
        <a href="http://rubyonrails.org/" class="article">
          <i class="article-icon is-ruby-on-rails"></i>
          <p class="article-name">Ruby on Rails</p>
        </a>
      </li>
      <li data-category-type="php">
        <a href="https://phalconphp.com/ja/" class="article">
          <i class="article-icon is-phalcon"></i>
          <p class="article-name">Phalcon</p>
        </a>
      </li>
      <li data-category-type="javascript">
        <a href="https://facebook.github.io/react/" class="article">
          <i class="article-icon is-react"></i>
          <p class="article-name">React</p>
        </a>
      </li>
      <li data-category-type="scala">
        <a href="https://www.playframework.com/" class="article">
          <i class="article-icon is-play"></i>
          <p class="article-name">Play</p>
        </a>
      </li>
      <li data-category-type="javascript">
        <a href="http://aurelia.io/" class="article">
          <i class="article-icon is-aurelia"></i>
          <p class="article-name">Aurelia</p>
        </a>
      </li>
      <li data-category-type="python">
        <a href="http://djangoproject.jp/" class="article">
          <i class="article-icon is-django"></i>
          <p class="article-name">Django</p>
        </a>
      </li>
      <li data-category-type="css">
        <a href="http://www.material-ui.com/#/" class="article">
          <i class="article-icon is-material-ui"></i>
          <p class="article-name">Material UI</p>
        </a>
      </li>
      <li data-category-type="php">
        <a href="https://laravel.com/" class="article">
          <i class="article-icon is-laravel"></i>
          <p class="article-name">Laravel</p>
        </a>
      </li>
    </ul>
  </div>
</div>
<script src="../../common/js/jquery.js"></script>
<script>
$(function() {
  $(".select").on('change',function(){
    var v=$(this).val();
    $('ul.list li').toggle(v=="All").filter('[data-category-type='+v+']').show();
  }).trigger('change');
});





.clearfix:after {
  display: block;
  clear: both;
  content: '';
}
.wrapper {
  padding: 20px;
}
.contents {
  margin: 0 auto;
  width: 300px;
}
.title {
  padding: 10px;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  background-color: #fff;
}
.select-wrapper {
  margin: 10px 0;
  text-align: right;
}
.select {
  padding: 10px;
  width: 100px;
  font-size: 14px;
  color: #fff;
  border: none;
  border-radius: 0;
  background-color: darkcyan;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  cursor: pointer;
  -webkit-appearance: none;
}
.list > li {
  border-top: 1px #eee solid;
}
.article {
  position: relative;
  display: table;
  padding: 10px;
  width: 100%;
  background-color: #fff;
  table-layout: fixed;
}
.article-icon {
  display: table-cell;
  width: 50px;
  height: 50px;
  background-size: cover;
}
.article-icon.is-bootstrap { background-image: url(../img/bootstrap.png); }
.article-icon.is-material-ui { background-image: url(../img/material-ui.png); }
.article-icon.is-react { background-image: url(../img/react.png); }
.article-icon.is-aurelia { background-image: url(../img/aurelia.png); }
.article-icon.is-ruby-on-rails { background-image: url(../img/ruby-on-rails.png); }
.article-icon.is-laravel { background-image: url(../img/laravel.png); }
.article-icon.is-phalcon { background-image: url(../img/phalcon.png); }
.article-icon.is-django { background-image: url(../img/django.png); }
.article-icon.is-play { background-image: url(../img/play.png); }
.article-name {
  display: table-cell;
  padding-left: 20px;
  width: 100%;
  font-size: 16px;
  font-weight: bold;
  vertical-align: middle;
}

<!doctype html>

jQueryFrameworks

AllCSSJavaScriptPHPRubyPythonScalaBootstrap

Ruby on Rails

Phalcon

React

Play

Aurelia

Django

Material UI

Laravel

$(function(){$(".select").on('change',function(){var v=$(this).val();$('ul.list li').toggle(v=="All").filter('[data-category-type='+v+']').show();}).trigger('change');});

.clearfix:after {
display: block;
clear: both;
content: '';
}
.wrapper {
padding: 20px;
}
.contents {
margin: 0 auto;
width: 300px;
}
.title {
padding: 10px;
font-size: 24px;
font-weight: bold;
text-align: center;
background-color: #fff;
}
.select-wrapper {
margin: 10px 0;
text-align: right;
}
.select {
padding: 10px;
width: 100px;
font-size: 14px;
color: #fff;
border: none;
border-radius: 0;
background-color: darkcyan;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
cursor: pointer;
-webkit-appearance: none;
}
.list > li {
border-top: 1px #eee solid;
}
.article {
position: relative;
display: table;
padding: 10px;
width: 100%;
background-color: #fff;
table-layout: fixed;
}
.article-icon {
display: table-cell;
width: 50px;
height: 50px;
background-size: cover;
}
.article-icon.is-bootstrap { background-image: url(../img/bootstrap.png); }
.article-icon.is-material-ui { background-image: url(../img/material-ui.png); }
.article-icon.is-react { background-image: url(../img/react.png); }
.article-icon.is-aurelia { background-image: url(../img/aurelia.png); }
.article-icon.is-ruby-on-rails { background-image: url(../img/ruby-on-rails.png); }
.article-icon.is-laravel { background-image: url(../img/laravel.png); }
.article-icon.is-phalcon { background-image: url(../img/phalcon.png); }
.article-icon.is-django { background-image: url(../img/django.png); }
.article-icon.is-play { background-image: url(../img/play.png); }
.article-name {
display: table-cell;
padding-left: 20px;
width: 100%;
font-size: 16px;
font-weight: bold;
vertical-align: middle;
}

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>jQuery</title>
<link rel="stylesheet" href="../../common/css/reset.css">
<link rel="stylesheet" href="../../common/css/base.css">
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<div class="wrapper">
  <div class="contents">
    <p class="title">Frameworks</p>
    <div class="select-wrapper">
      <select class="select">
        <option value="all">All</option>
        <option value="css">CSS</option>
        <option value="javascript">JavaScript</option>
        <option value="php">PHP</option>
        <option value="ruby">Ruby</option>
        <option value="python">Python</option>
        <option value="scala">Scala</option>
      </select>
    </div>
    <ul class="list">
      <li data-category-type="css">
        <a href="http://getbootstrap.com/" class="article">
          <i class="article-icon is-bootstrap"></i>
          <p class="article-name">Bootstrap</p>
        </a>
      </li>
      <li data-category-type="ruby">
        <a href="http://rubyonrails.org/" class="article">
          <i class="article-icon is-ruby-on-rails"></i>
          <p class="article-name">Ruby on Rails</p>
        </a>
      </li>
      <li data-category-type="php">
        <a href="https://phalconphp.com/ja/" class="article">
          <i class="article-icon is-phalcon"></i>
          <p class="article-name">Phalcon</p>
        </a>
      </li>
      <li data-category-type="javascript">
        <a href="https://facebook.github.io/react/" class="article">
          <i class="article-icon is-react"></i>
          <p class="article-name">React</p>
        </a>
      </li>
      <li data-category-type="scala">
        <a href="https://www.playframework.com/" class="article">
          <i class="article-icon is-play"></i>
          <p class="article-name">Play</p>
        </a>
      </li>
      <li data-category-type="javascript">
        <a href="http://aurelia.io/" class="article">
          <i class="article-icon is-aurelia"></i>
          <p class="article-name">Aurelia</p>
        </a>
      </li>
      <li data-category-type="python">
        <a href="http://djangoproject.jp/" class="article">
          <i class="article-icon is-django"></i>
          <p class="article-name">Django</p>
        </a>
      </li>
      <li data-category-type="css">
        <a href="http://www.material-ui.com/#/" class="article">
          <i class="article-icon is-material-ui"></i>
          <p class="article-name">Material UI</p>
        </a>
      </li>
      <li data-category-type="php">
        <a href="https://laravel.com/" class="article">
          <i class="article-icon is-laravel"></i>
          <p class="article-name">Laravel</p>
        </a>
      </li>
    </ul>
  </div>
</div>
<script src="../../common/js/jquery.js"></script>
<script>
$(function() {
  $(".select").on('change',function(){
    var v=$(this).val();
    $('ul.list li').toggle(v=="All").filter('[data-category-type='+v+']').show();
  }).trigger('change');
});





.clearfix:after {
  display: block;
  clear: both;
  content: '';
}
.wrapper {
  padding: 20px;
}
.contents {
  margin: 0 auto;
  width: 300px;
}
.title {
  padding: 10px;
  font-size: 24px;
  font-weight: bold;
  text-align: center;
  background-color: #fff;
}
.select-wrapper {
  margin: 10px 0;
  text-align: right;
}
.select {
  padding: 10px;
  width: 100px;
  font-size: 14px;
  color: #fff;
  border: none;
  border-radius: 0;
  background-color: darkcyan;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
  cursor: pointer;
  -webkit-appearance: none;
}
.list > li {
  border-top: 1px #eee solid;
}
.article {
  position: relative;
  display: table;
  padding: 10px;
  width: 100%;
  background-color: #fff;
  table-layout: fixed;
}
.article-icon {
  display: table-cell;
  width: 50px;
  height: 50px;
  background-size: cover;
}
.article-icon.is-bootstrap { background-image: url(../img/bootstrap.png); }
.article-icon.is-material-ui { background-image: url(../img/material-ui.png); }
.article-icon.is-react { background-image: url(../img/react.png); }
.article-icon.is-aurelia { background-image: url(../img/aurelia.png); }
.article-icon.is-ruby-on-rails { background-image: url(../img/ruby-on-rails.png); }
.article-icon.is-laravel { background-image: url(../img/laravel.png); }
.article-icon.is-phalcon { background-image: url(../img/phalcon.png); }
.article-icon.is-django { background-image: url(../img/django.png); }
.article-icon.is-play { background-image: url(../img/play.png); }
.article-name {
  display: table-cell;
  padding-left: 20px;
  width: 100%;
  font-size: 16px;
  font-weight: bold;
  vertical-align: middle;
}
ソース リンク

Jqueryを使って、ソート機能を実装しようとしているのですが、別の書き方を模索しています。

Jqueryを使って、別の書き方を模索しています。
現在ソート機能を下記のやり方で実装したいと思っています。
個人的には今書いてあるものでも行けると思っているのですが、下記の要素を使った際だとどのような実装になるのか勉強させていただきたいです。
.show() 要素を表示させる
.hide() 要素を隠す
.val() 要素のvalueを取得
.data('') DOM要素にあるdata-~を取得できる
.change() セレクトボックスの値の変更をキャッチする関数
$().each() DOM要素を1つずつループ処理をする(ループ内で$(this)を使うと要素がひとつずつ取得できる)

<!doctype html>

jQuery Frameworks

All CSS JavaScript PHP Ruby Python Scala Bootstrap

Ruby on Rails

Phalcon

React

Play

Aurelia

Django

Material UI

Laravel

$(function() { $(".select").on('change',function(){ var v=$(this).val(); $('ul.list li').toggle(v=="All").filter('[data-category-type='+v+']').show(); }).trigger('change'); });

.clearfix:after {
display: block;
clear: both;
content: '';
}
.wrapper {
padding: 20px;
}
.contents {
margin: 0 auto;
width: 300px;
}
.title {
padding: 10px;
font-size: 24px;
font-weight: bold;
text-align: center;
background-color: #fff;
}
.select-wrapper {
margin: 10px 0;
text-align: right;
}
.select {
padding: 10px;
width: 100px;
font-size: 14px;
color: #fff;
border: none;
border-radius: 0;
background-color: darkcyan;
box-shadow: 0 1px 2px rgba(0, 0, 0, .4);
cursor: pointer;
-webkit-appearance: none;
}
.list > li {
border-top: 1px #eee solid;
}
.article {
position: relative;
display: table;
padding: 10px;
width: 100%;
background-color: #fff;
table-layout: fixed;
}
.article-icon {
display: table-cell;
width: 50px;
height: 50px;
background-size: cover;
}
.article-icon.is-bootstrap { background-image: url(../img/bootstrap.png); }
.article-icon.is-material-ui { background-image: url(../img/material-ui.png); }
.article-icon.is-react { background-image: url(../img/react.png); }
.article-icon.is-aurelia { background-image: url(../img/aurelia.png); }
.article-icon.is-ruby-on-rails { background-image: url(../img/ruby-on-rails.png); }
.article-icon.is-laravel { background-image: url(../img/laravel.png); }
.article-icon.is-phalcon { background-image: url(../img/phalcon.png); }
.article-icon.is-django { background-image: url(../img/django.png); }
.article-icon.is-play { background-image: url(../img/play.png); }
.article-name {
display: table-cell;
padding-left: 20px;
width: 100%;
font-size: 16px;
font-weight: bold;
vertical-align: middle;
}