要素にマウスを乗せると表示されるシンプルなツールチップ

Ads

Result

jQuery

this.t_tip = function() {
    //ツールチップの出る場所
    this.xOffset = -10; 
    this.yOffset = 20;        
    //マウスホバーイベント
    $(".tooltip").unbind().hover(
        function(e) {
            //要素のtitle属性を取得してspanの中に含める
            this.t = this.title;
            this.title = '';
            this.top = (e.pageY + yOffset); 
            this.left = (e.pageX + xOffset);
            $('body').append( '<span id="tip_body">' + this.t + '</span>' );
            $('#tip_body').css("top", this.top+"px").css("left", this.left+"px").fadeIn("farst");
        },
        function() {
            this.title = this.t;
            $("#tip_body").remove();
        }
    //マウスの動きに合わせる
    ).mousemove(
        function(e) {
            this.top = (e.pageY + yOffset);
            this.left = (e.pageX + xOffset);
            $("#tip_body").css("top", this.top+"px").css("left", this.left+"px");
        }
    );            
};
jQuery(document).ready(function($){t_tip();})

css

p{font-size:12px; line-height:16px;}
a{color:red ;}

#tip_body { /*ツールチップのデザイン*/
    display: none; 
    position: absolute; 
    padding: 10px; 
    left: 5px; 
    font-size: 0.8em; 
    background-color: #333; 
    color:#fff;
    border: 1px solid red; 
    opacity: 0.9 ;
    filter:progid:DXImageTransform.Microsoft.Alpha(Enabled=1,Style=0,Opacity=90) ;
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px; 
    z-index: 9999; }

html

<p><a href="http://wp-shotoku.com/about-shotoku/" class="tooltip" title="Minimal, Responsive, Gallery WordPress theme for FREE!!">Shotoku</a></p>

via

vtip – from www.­vertigo-­project.­com

タイトルとURLをコピーしました