Ads 468x60px

Labels

Wednesday, March 5, 2014

How to create a tooltips with jQuery

simple idea to create a tooltips
HTML
<input type="text" title="Here put your toottips text " />
CSS
.autoSugest{background:#fffdef;border:1px solid #cac6ad;
-webkit-border-radius:4px;
-moz-border-radius:4px;
border-radius:4px;color:#7f7943;
display:none;
font-size:12px;
padding:7px 15px;
position:absolute;
min-width:100px;
-o-box-sizing:border-box;
-ms-box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
box-sizing:border-box;}
.autoSugest:after{
content:url("../../images/tootl-tip-arrow.png"); height:8px;
width:11px;
position:absolute;
top:-13px;
left:38px}
Jquery
$.fn.autoSuggest = function(){ return this.each(function(index, elm){
if(!$(elm).is('[data-title]')){
$(elm).attr('data-title', $(elm).attr('title')).attr('title', '');
};

$(elm).on('focus', function(){
var element = $(this),
posTop = element.offset().top + element.outerHeight() + 10,
posLeft = element.offset().left,
toolTipWidth = element.outerWidth() > 90 ? element.outerWidth() : 250,
titleText = element.attr('data-title');
if(titleText && titleText != ''){
$('<div />', {class: 'autoSugest', text : titleText, css : {left: posLeft, top: posTop, maxWidth: toolTipWidth}}).appendTo('body').fadeIn();
}else{
return false;
}
});
$(elm).on('blur', function(){
$('.autoSugest').fadeOut(function(){
$(this).remove();
});
});
}); };
$(document).ready(function(){
    $('input[title]').autoSuggest(); });
 

0 comments:

Post a Comment