jquery - Tooltip add second style -
i have 2 tooltips on page, i'm using code below wanted add second 'rel=' somehow don't have duplicate jquery, plan add 1 div tooltip id shown in code , 1 class of tooltip2 1 styles differently. i've fiddled around this quite bit , can't work out how separate class in there.
the main aim make tooltip 2 black white text popup.
i've got jsfiddle i've been working on: http://jsfiddle.net/xjz9v/
jquery:
$( document ).ready( function() { var targets = $( '[rel~=tooltip]' ), target = false, tooltip = false, title = false; targets.bind( 'mouseenter', function() { target = $( ); tip = target.attr( 'title' ); tooltip = $( '<div id="tooltip"></div>' ); if( !tip || tip == '' ) return false; target.removeattr( 'title' ); tooltip.css( 'opacity', 0 ) .html( tip ) .appendto( 'body' ); var init_tooltip = function() { if( $( window ).width() < tooltip.outerwidth() * 1.5 ) tooltip.css( 'max-width', $( window ).width() / 2 ); else tooltip.css( 'max-width', 340 ); var pos_left = target.offset().left + ( target.outerwidth() / 2 ) - ( tooltip.outerwidth() / 2 ), pos_top = target.offset().top - tooltip.outerheight() - 20; if( pos_left < 0 ) { pos_left = target.offset().left + target.outerwidth() / 2 - 20; tooltip.addclass( 'left' ); } else tooltip.removeclass( 'left' ); if( pos_left + tooltip.outerwidth() > $( window ).width() ) { pos_left = target.offset().left - tooltip.outerwidth() + target.outerwidth() / 2 + 20; tooltip.addclass( 'right' ); } else tooltip.removeclass( 'right' ); if( pos_top < 0 ) { var pos_top = target.offset().top + target.outerheight(); tooltip.addclass( 'top' ); } else tooltip.removeclass( 'top' ); tooltip.css( { left: pos_left, top: pos_top } ) .animate( { top: '+=10', opacity: 1 }, 50 ); }; init_tooltip(); $( window ).resize( init_tooltip ); var remove_tooltip = function() { tooltip.animate( { top: '-=10', opacity: 0 }, 50, function() { $( ).remove(); }); target.attr( 'title', tip ); }; target.bind( 'mouseleave', remove_tooltip ); tooltip.bind( 'click', remove_tooltip ); }); }); css:
.infotooltip{ background-color: #d7df23; display: inline-block; height: 18px; width: 18px; color: #000; line-height: 28px; font-size: 28px; padding: 2px 5px 8px 5px; text-align: center; position: relative; font-family: 'im fell english', serif; font-style: italic; margin: -5px 0 -5px 5px; font-weight: normal; cursor: default; -webkit-border-radius: 14px; -moz-border-radius: 14px; border-radius: 14px; -webkit-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.4); box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.4); z-index: 1; text-decoration: none; } .bondten { text-align: center; color: #ffffff; background: #000000; } .bondten:after /* triangle decoration */ { border-top: 10px solid #000000; } #tooltip { text-align: center; color: #000000; background: #d7df23; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.4); box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.4); position: absolute; z-index: 100; padding: 15px; } #tooltip:after /* triangle decoration */ { width: 0; height: 0; border-left: 10px solid transparent; border-right: 10px solid transparent; border-top: 10px solid #d7df23; content: ''; position: absolute; left: 50%; bottom: -10px; margin-left: -10px; } #tooltip.top:after { border-top-color: transparent; border-bottom: 10px solid #d7df23; top: -20px; bottom: auto; } #tooltip.left:after { left: 10px; margin: 0; } #tooltip.right:after { right: 10px; left: auto; margin: 0; } .bondtentooltip{ float: none !important; font-family: 'chevinprodemibold'; font-size: 22px; padding: 0 5px 10px; -webkit-box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2); box-shadow: 1px 1px 1px 0px rgba(0, 0, 0, 0.2); background-color: #fff; display: inline-block; height: 18px; width: 18px; color: #666; line-height: 28px; text-align: center; position: relative; font-style: normal; margin: -5px 0 -5px 25px; font-weight: normal; cursor: default; -webkit-border-radius: 14px; -moz-border-radius: 14px; border-radius: 14px; z-index: 1; } html:
<abbr title="tooltip 1" class="bondtentooltip" rel="tooltip">1</abbr> <abbr title="tooltip 2" class="bondtentooltip" rel="tooltip">2</abbr>
you need add 1 more class have against tooltip 2:
<abbr title="tooltip 2" class="bondtentooltip bondten" rel="tooltip">2</abbr> and move .bondten class declaration after .bondtentooltip
additionally, if want change tooltip itself, take here
edit fixed work in chrome. fiddle
Comments
Post a Comment