【JavaScript/CSS】鼠标mouseover时文字提示
2012-11-01 14:20 Simon.Jiang 阅读(1327) 评论(0) 编辑 收藏 举报//方法定义
Ctrip.tooltip = function(sel){ var tip = document.createElement('div'); tip.id = "titleTip"; tip.innerHTML = '<b class="tri_t"></b><div id="contentTip"></div>'; var ori = ''; var hideTimer = ''; var isTrigger = false; document.body.appendChild(tip); sel.bind('mouseover',function(e){ ori = this.title; this.title = ''; if(ori != ''){ $('#contentTip').html(ori); var ofTop = $(this).offset().top + 22; var ofLeft = $(this).offset().left; $('#titleTip')[0].style.top = ofTop +'px'; $('#titleTip')[0].style.left = ofLeft +'px'; $('#titleTip').css('display','block'); } /*$('#titleTip').bind('mouseout',function(e){ console.log('trigger222'); var self = $(this); setTimeout(function(){ self.hide(); },500) })*/ e.preventDefault(); }) sel.bind('mouseout',function(e){ this.title = ori; $('#titleTip').hide(); isTrigger= false; }) }
//方法使用 Ctrip.tooltip($('.icon_desc_text')); //样式文件 #titleTip {padding:5px; border: 1px solid #67A1E2;width:200px;position:absolute;display:none;z-index:100;background:#fff;} .tri_t{position: absolute;width: 16px;height: 16px;background-image: url(http://pic.ctrip.com/common/un_jmp_tri.png);background-position: -32px 0;background-repeat: no-repeat; overflow: hidden;margin-top: -12px; left: 0px; }