How to set tooltip in bootstrap on mouse over.

Link bootstrap css and js file.
Then link below script.
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

Now put below html for tooltip.
<span  data-toggle="tooltip" data-placement="right" title="what have to show in tooltip">hover tooltip show </span>

Write below script for tooltip.
$(function () {
        $('[data-toggle="tooltip"]').tooltip({
            html: true,
            trigger: 'manual'
        }).on("mouseenter", function () {
            var _this = this;
            $(_this).tooltip("show");
            $(_this).siblings(".tooltip").on("mouseleave", function () {
                $(_this).tooltip('hide');
            });
        }).on("mouseleave", function () {
            var _this = this;
            setTimeout(function () {
                if (!$(".tooltip:hover").length) {
                    $(_this).tooltip("hide")
                }
            }, 100);
        });
        $('[data-toggle="tooltip"]').hover(function () {
           var pos = positionTooltip(this);
            $('.tooltip-inner').css('color', '#12677C');
            $('.tooltip-inner').css('TEXT-DECORATION', 'none');
            $('.tooltip-inner').css('background-color', '#ffffff');
            $('.tooltip-inner').css('text-align', 'left');
            $('.tooltip-inner').css('font-family', 'GothamBook, Century Gothic, Calibri, sans-serif');
            $('.tooltip-inner').css('font-size', '13');
            $('.tooltip-inner').css('min-width', '200px');
            $('.tooltip-inner').css('max-width', '500px');
            $('.tooltip-inner').css('max-height', '200px');
            $('.tooltip-inner').css('overflow', 'auto');
            $('.tooltip').css('top', pos+'px');
        });
Below function is for tooltip position adjustment.

functionpositionTooltip(currentElement) {
        varposition = $(currentElement).position();
        if(position.top < 60) {
            return 0;
        }
    }

No comments:

Post a Comment