1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

リサイズ時にTooltipをリアルタイムで表示する

Last updated at Posted at 2017-01-28

画面項目をリサイズする時にTooltipをリアルタイムで表示する方法を検証しました。
完成後のイメージ
スクリーンショット 2017-01-28 13.14.41.png

実装

1.HTMLで画面項目を用意します。

<div id="demoDIV" style="width:200px; height:100px">
    <p>DEMO</p>
</div>

2.上記のDIVに対して、Tooltipを定義します。

$("#demoDIV").tooltip({
    items: $("#demoDIV"),
    track: true,
    content: updateTooltipContent,
    show: { effect:"none", delay:0},
    hide: { when: 'mouseout' }
});

3.DIVのリサイズを可能にし、リサイジング際にTooltipをリアルタイムで表示させます。

$("#demoDIV").resizable({
    resize: function (event, ui) {
        $("#demoDIV").tooltip("option", "content", updateTooltipContent);
    }
});

4,Tooltipに表示する内容と定義します。

function updateTooltipContent() {
    return $("#demoDIV").css("width")+ "" +$("#demoDIV").css("height");
}

ソースコード

<!DOCTYPE HTML>
<HTML>
    <head>
        <meta charset="UTF-8" />
        <title>DEMO</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
        <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/ui-lightness/jquery-ui.css">
        
        <style type="text/css">
            
            body {
                padding:0px;
                font:14px/1.5 Lato, "Helvetica Neue", Helvetica, Arial, sans-serif;
                color:#777;
                font-weight:300;
            }
            
            div {
                background-color: #F4F9EE;
            }
                
        </style>
        
        <script>
            
            $(function(){
                
                $("#demoDIV").tooltip({
                    items: $("#demoDIV"),
                    track: true,
                    content: updateTooltipContent,
                    show: { effect:"none", delay:0},
                    hide: { when: 'mouseout' }
                });
                
                $("#demoDIV").resizable({
                    
                    resize: function (event, ui) {
                        $("#demoDIV").tooltip("option", "content", updateTooltipContent);
                    }
                });
                
                function updateTooltipContent() {
                    return $("#demoDIV").css("width")+ "" +$("#demoDIV").css("height");
                }
            })
            
        </script>
        
    </head>

    <body>
        <div id="demoDIV" style="width:200px; height:100px">
            <p>DEMO</p>
        </div>
    </body>
</HTML>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?