 
                            jQueryはもう不要?2019年のフロントエンド事情を考えてみる
 もきち
                    もきち
                 じーよ
                        じーよ
                     
                                    こんにちは。じーよです。
今回はjquery.pep.jsを使って要素を自由に動かせるようにします。
今回利用するjquery.pep.jsを以下のページからダウンロードしてください。
https://github.com/briangonzalez/jquery.pep.js/
ダウンロードしたjquery.pep.jsをプロジェクトディレクトリーに置く
ダウンロードしたファイルを解凍し、以下二つのファイルをコピーし、導入したいWebサイトのディレクトリ内に置いてください。
その後HTMLファイルでファイルを読み込みます。
| 1 2 | <script type="text/javascript" src="jquery-1.7.2.min.js"></script> <script type="text/javascript" src="jquery.pep.js"></script> | 
| 1 | <h3 class="sample1">動く要素です</h3> | 
| 1 2 3 | $(document).ready(function(){ $('.sample').pep(); }); | 

| 1 2 3 4 5 6 7 | <div class="sample2">       <div class="block1"></div>       <h3 class="sample2_01">動く要素です</h3>       <h3 class="sample2_02">縦</h3>       <h3 class="sample2_03">横</h3>       <h3 class="sample2_04">縦横</h3> </div> | 
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | *{     box-sizing: border-box;     margin: 0px;     padding: 0px; } .sec2{     position: relative;     height: 50vh;     width: calc(100vw - 30px);     margin:15px;     border: 3px lightslategray solid; } .block1{     position: absolute;     bottom: 0;     height: 100px;     width: 100%;     background-color: lightcoral; } .pep-dpa{     background-color: indianred; } | 
| 1 2 3 4 | $('.sample2_01').pep({droppable: '.droppable',constrainTo: 'parent'}); $('.sample2_02').pep({droppable: '.droppable',axis: 'y',constrainTo: 'parent'}) ; $('.sample2_03').pep({droppable: '.droppable',axis: 'x',constrainTo: 'parent'}) ; $('.sample2_04').pep({droppable: '.droppable',axis: 'auto',constrainTo: 'parent'}); | 
ドラッグ&ドロップしたい要素のクラス名を入力するだけで簡単に実装することができるので使ってみてはいかがでしょうか。
jquery.pep.jsはまだ紹介していないオプションが多数あるので、詳しく知りたい方はこちらをご覧ください。
POPULAR
 
                        じーよ
Frontend Engineer
人気記事