2014年12月31日水曜日

jQuery+CSSでウィンドウの拡大・縮小をやってみた。

jQuery+CSSでウィンドウの拡大・縮小を再現してみた。



Window.html

<!DOCTYPE html>

<html>

    <head>

        <title>TODO supply a title</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link rel="stylesheet" href="./css/Window.css">

        <script src="./js/vendor/jquery-2.1.1.js"></script>

        <script src="./js/vendor/jquery-ui.js"></script>

        <script src="./js/Window.js"></script>

    </head>

    <body>

       

        <button class="show">ウィンドウを表示</button>

       

        <div class="window">

            <div class="title">

                ウィンドウのタイトル

            </div>

            <button class="minimize">-</button>

            <button class="maximize">□</button>

            <button class="close">×</button>

            <div class="content">

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

               

            </div>

        </div>

    </body>

</html>


Window.css
.window {

    position:relative;

    width: 260px;

    height: 180px;

    border-style: solid;

    border-width: 2px;

    border-color: rgb(150, 150, 150);

    background: rgb(218, 218, 218);

}



.window > .title {

    position: absolute;

    left: 0px;

    display: inline-block;

    background-color: rgb(0, 0, 230);

    border-color: rgb(0, 0, 180);

    border-width: 2px;

    height: 20px;

    width: 260px;

    margin: 0px;

    color: white;

}



.window > button {

    position: absolute;

    display: inline-block;

    border-width: 2px;

    border-style: solid;

    border-color: rgb(150, 150, 150);

    background-color: rgb(218, 218, 218);

    height: 20px;

    margin: 0px;

}



.window > .minimize {

    right: 40px;

}

.window > .maximize {

    right: 20px;

}

.window > .close {

    right: 0px;

}



.window > .content {

    position: relative;

    display: block;

    overflow: scroll;

    top: 20px;

    width: 260px;

    height: 160px;

}



.show {

    position: relative;

    display: block;

    top: 0px;

    left: 0px;

}
Window.js

$(function(){

   

    var $window = $('.window'),

        $maximize = $window.find('.maximize'),

        $minimize = $window.find('.minimize'),

        $close = $window.find('.close'),

        $title = $window.find('.title'),

        $contents = $window.find('.content'),

        $showButton = $('.show'),

        $baseWindow = $(window);

       

    var width = $baseWindow.width(),

        height = $baseWindow.height();

   

    var originalWidth = $window.width(),

        originalHeight = $window.height();

    

    var duration = 750;

   

    var windowWidth = $window.width();

    $title.css({ width: windowWidth+'px' });

   

    $close.on('click', function(){

        $window.css({ display: 'none' });

    });

   

    $maximize.on('click', function(){

        width = $baseWindow.width();

        height = $baseWindow.height();

        $(this).toggleClass('maximized');

        if($(this).hasClass('maximized')){

            $window.stop(true).animate({

                top: '0px',

                left: '0px',

                width: width+'px',

                height: height+'px'

            }, {

                duration: duration,

                queue: false

            });

            $title.stop(true).animate({

                width: width+'px'

            },{

                duration: duration,

                queue: false

            });

            $contents.stop(true).animate({

                width: width+'px',

                height: height+'px'

            },{

                duration: duration,

                euque: false

            });

        } else {

            $window.stop(true).animate({

                top: '0px',

                left: '0px',

                width: originalWidth+'px',

                height: originalHeight+'px'

            }, {

                duration: duration,

                queue: false

            });

            $title.stop(true).animate({

                width: originalWidth+'px'

            },{

                duration: duration,

                queue: false

            });

            $contents.stop(true).animate({

                width: originalWidth+'px',

                height: originalHeight+'px'

            },{

                duration: duration,

                euque: false

            });

        }

    });

   

    $showButton.on('click', function(){

        $window.css({ display: 'inline-block' });

    });

   

});



jQuery+CSSでウィンドウの表示・非表示を再現してみた。


jQuery+CSSでウィンドウの表示非常時を再現してみた。

以下がイメージ動画。
Window.html


    
        TODO supply a title
        
        
        
        
        
        
    
    
        
        
        
        
ウィンドウのタイトル
コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。 コンテンツの内容はこんな感じですよ。
<!DOCTYPE html> <html>     <head>         <title>TODO supply a title</title>         <meta charset="UTF-8">         <meta name="viewport" content="width=device-width, initial-scale=1.0">         <link rel="stylesheet" href="./css/Window.css">         <script src="./js/vendor/jquery-2.1.1.js"></script>         <script src="./js/vendor/jquery-ui.js"></script>         <script src="./js/Window.js"></script>     </head>     <body>                 <button class="show">ウィンドウを表示</button>                 <div class="window">             <div class="title">                 ウィンドウのタイトル             </div>             <button class="minimize">-</button>             <button class="maximize">□</button>             <button class="close">×</button>             <div class="content">                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                 コンテンツの内容はこんな感じですよ。                             </div>         </div>     </body> </html>


Window.css

.window {

    position:relative;

    width: 260px;

    height: 180px;

    border-style: solid;

    border-width: 2px;

    border-color: rgb(150, 150, 150);

    background: rgb(218, 218, 218);

}



.window > .title {

    position: absolute;

    left: 0px;

    display: inline-block;

    background-color: rgb(0, 0, 230);

    border-color: rgb(0, 0, 180);

    border-width: 2px;

    height: 20px;

    width: 260px;

    margin: 0px;

    color: white;

}



.window > button {

    position: absolute;

    display: inline-block;

    border-width: 2px;

    border-style: solid;

    border-color: rgb(150, 150, 150);

    background-color: rgb(218, 218, 218);

    height: 20px;

    margin: 0px;

}



.window > .minimize {

    right: 40px;

}

.window > .maximize {

    right: 20px;

}

.window > .close {

    right: 0px;

}



.window > .content {

    position: relative;

    display: block;

    overflow: scroll;

    top: 20px;

    width: 260px;

    height: 160px;

}



.show {

    position: relative;

    display: block;

    top: 0px;

    left: 0px;

}



Window.js

$(function(){

   

    var $window = $('.window'),

        $maximize = $window.find('.maximize'),

        $minimize = $window.find('.minimize'),

        $close = $window.find('.close'),

        $title = $window.find('.title'),

        $contents = $window.find('.content'),

        $showButton = $('.show'),

        $baseWindow = $(window);



    $close.on('click', function(){

        $window.css({ display: 'none' });

    });

   



   

    $showButton.on('click', function(){

        $window.css({ display: 'inline-block' });

    });

   

});



CSS書いてみた

CSSで昔日のWindowsのウィンドウを作ってみた。

















CSSのクラス設計とかについては無視希望。

Window.css

.window {
    position:relative;
    top: 180px;
    left: 180px;
    width: 260px;
    height: 180px;
    border-style: solid;
    border-width: 2px;
    border-color: rgb(150, 150, 150);
    background: rgb(218, 218, 218);
}

.window > .title {
    position: absolute;
    left: 0px;
    display: inline-block;
    background-color: rgb(0, 0, 230);
    border-color: rgb(0, 0, 180);
    border-width: 2px;
    height: 20px;
    width: 220px;
    margin: 0px;
    color: white;
}

.window > button {
    position: absolute;
    display: inline-block;
    border-width: 2px;
    border-style: solid;
    border-color: rgb(150, 150, 150);
    background-color: rgb(218, 218, 218);
    height: 20px;
    margin: 0px;
}

.window > .minimize {
    right: 40px;
}
.window > .maximize {
    right: 20px;
}
.window > .close {
    right: 0px;
}

.window > .content {
    position: relative;
    display: block;
    overflow: scroll;
    top: 20px;
    width: 260px;
    height: 160px;
}

Window.html

<!DOCTYPE html>

<html>

    <head>

        <title>TODO supply a title</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

        <link rel="stylesheet" href="./css/Window.css">

        <script src="./js/vendor/jquery-2.1.1.js"></script>

        <script src="./js/vendor/jquery-ui.js"></script>

        <script src="./js/Window.js"></script>

    </head>

    <body>

        <div class="window">

            <div class="title">

                ウィンドウのタイトル

            </div>

            <button class="minimize">-</button>

            <button class="maximize">□</button>

            <button class="close">×</button>

            <div class="content">

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

                コンテンツの内容はこんな感じですよ。

               

            </div>

        </div>

    </body>

</html>


2014年12月21日日曜日

jQueryのお勉強(2) 

現在下記のテキストを使ってjQueryを学習中です。


とは言いつつもCSSの知識不足が絶望的なので、
セレクタの選択方法を整理。

セレクタの指定方法

基本的な指定方法

1) 単一のセレクタを指定
セレクタ {
    プロパティ: 値
}
 2) 複数のセレクタを一括指定
セレクタ1, セレクタ2, ... {
    プロパティ: 値
}

親子関係を利用した指定方法

1) スペース区切り
スペース区切りでセレクタを指定した場合は、
子要素で指定したセレクタが親要素内部に含まれた場合
のみ書式変更の対象となります。
直接の親-子関係だけでなく、祖父母-孫の関係でも
適用されます。
親要素 子要素 {
    プロパティ: 値
}
2) > 区切り
> で区切った場合は、直接の親子関係にある場合のみ、
書式変更の対象となります。

親要素 > 子要素 {
    プロパティ: 値
}

他にもいろいろあるけど、
まだ使うことによる利益がまだわからなかったり、
教科書を読み解く上では不要だったりするので
いったんは放置。









2014年12月14日日曜日

jQueryのお勉強(1)

遅ればせながらjQueryのお勉強を始めました。


個人的に作ってるツールのUI改善のためにお勉強です。

JavaScriptに触るのが、4年ぶりというアレな状態ですが...

インフラエンジニアなので、UI周りは疎いので自分のもってる技術領域を広げる意味も
含めてトライ。

テキストに使うのは下のこれ。
よいものかはよくわかっていないですが、一通り基本が身に付きそうなので



jQuery最高の教科書


学んだことをちょくちょくメモとしてアップデートしていこうかと思います。