对话框/Tips

jQuery和css3滑动显示tooltips工具提示

阿里云

这是一款使用 jQuery 和 css3 制作的滑动显示 tooltips 工具提示特效。该 tooltips 工具提示特效以滑动展开的方式显示特定链接的详细信息,整个动画过渡自然,效果非常酷。这个 tooltips 工具提示插件可以从 4 个方向打开:右下(默认)、左下、左上和右上。还可以选择 3 种颜色:绿色(默认)、蓝色和红色。

HTML 结构:

要创建这个 tooltips 工具提示效果,你需要使用 p 标签,这意味着 tooltips 的内容对搜索引擎是可见的。在页面加载的时候,p 标签的内容被用 jQuery 替换为滑动面板中的内容。

也想出现在这里?联系我们
创客主机
  1. <div class="main">
  2.  <p title="A New Tutorial Every Week" style="top:200px;left:120px;">
  3.   This slideout is going to open to the bottom-right (the default).
  4.  </p>
  5.  <p title="2200+ Twitter Followers" class="openTop openLeft blue" style="top:400px;left:650px;">
  6.   This slideout is going to open to the top-left.
  7.  </p>
  8.  <p title="Over 5000 RSS Subscribers" class="openTop red" style="top:500px;left:90px;">
  9.   This slideout is going to open to the top-right.
  10.  </p>
  11. </div>

如上所示,每一个标签都带有一个 style 和一个 class。当使用 jQuery 替换滑动面板时,这些属性一起被复制过去。style 属性决定了滑动面板在父元素中的位置,也就是说,滑动面板的位置和 p 标签的位置是相同的。class 属性是可选的,它为滑动面板提供一些可选参数。你可以旋转打开的方向或是面板的颜色。

  1. <div class="slideOutTip openLeft blue" style="left:100px;top:200px">
  2.  <div class="tipVisible">
  3.   <div class="tipIcon"><div class="plusIcon"></div></div>
  4.   <p class="tipTitle">The title of the slideout</p>
  5.  </div>
  6.  
  7.  <div class="slideOutContent">
  8.   <p>Slideout Content</p>
  9.  </div>
  10. </div>

jQuery和css3滑动显示tooltips工具提示

CSS 样式:

下面只列出了滑动面板的样式:

  1. .slideOutTip{
  2.  /* The main wrapping div of the slideout tips */
  3.  position:absolute;
  4.  padding:3px;
  5.  top:0;
  6.  left:0;
  7.  background-color:#111;
  8.  font-size:13px;
  9.  color:white;
  10.  overflow:hidden;
  11.  height:22px;
  12. }
  13.  
  14. .slideOutTip:hover{
  15.  /* Applying a CSS3 outer glow on hover */
  16.  -moz-box-shadow:0 0 1px #999;
  17.  -webkit-box-shadow:0 0 1px #999;
  18.  box-shadow:0 0 1px #999;
  19. }
  20.  
  21. /* The holder for the title and the icon: */
  22. .tipVisible{ cursor:pointer; height:22px; }
  23.  
  24. .tipTitle{
  25.  float:left;
  26.  font-family:'Myriad Pro',Arial, Helvetica, sans-serif;
  27.  font-size:15px;
  28.  font-weight:bold;
  29.  white-space:nowrap;
  30.  line-height:22px;
  31.  padding-right:5px;
  32. }
  33.  
  34. .tipIcon{
  35.  width:20px;
  36.  height:20px;
  37.  float:left;
  38.  background-color:#61b035;
  39.  border:1px solid #70c244;
  40.  margin-right:8px;
  41.  
  42.  /* CSS3 Rounded corners */
  43.  
  44.  -moz-border-radius:1px;
  45.  -webkit-border-radius:1px;
  46.  border-radius:1px;
  47. }

开始的时候,tooltips 面板只有标题和一个图标是可见的,然后在后面使用 jQuery 为它们绑定 click 事件,当用户点击时滑动面板展开。

  1. /* Three color themes */
  2. .green .tipIcon{ background-color:#61b035; border:1px solid #70c244; }
  3. .blue .tipIcon{ background-color:#1078C7; border:1px solid #1e82cd; }
  4. .red .tipIcon{ background-color:#CD3A12; border:1px solid #da421a; }
  5.  
  6. .plusIcon{
  7.  /* The plus icon */
  8.  width:13px;
  9.  height:13px;
  10.  background:url('img/plus.gif') no-repeat center center;
  11.  margin:4px;
  12.  
  13.  /* Defining a CSS3 animation. Currently only works in Chrome and Safari */
  14.  -webkit-transition: -webkit-transform 0.2s linear;
  15.  -moz-transition: -moz-transform 0.2s linear;
  16.  transition: transform 0.2s linear;
  17. }
  18.  
  19. .slideOutTip.isOpened{ z-index:10000; }
  20.  
  21. .slideOutTip.isOpened .plusIcon{
  22.  /* Applying a CSS3 rotation  to the opened slideouts*/
  23.  -moz-transform:rotate(45deg);
  24.  -webkit-transform:rotate(45deg);
  25.  transform:rotate(45deg);
  26. }
  27.  
  28. /* Special rules for the left and top - opening versions */
  29.  
  30. .openLeft .tipIcon{
  31.  /* Floating the title and the icon to the right */
  32.  margin:0 0 0 8px;
  33.  float:right;
  34. }
  35. .openLeft .tipTitle{ float:right; padding:0 0 0 5px; }
  36. .openLeft .slideOutContent{ margin-top:22px; }
  37. .openLeft.openTop .slideOutContent{ margin-top:0; }
  38.  
  39. .slideOutContent{
  40.  /* Hiding the div with the slide out content: */
  41.  display:none;
  42.  padding:10px;
  43.  font-size:11px;
  44. }
  45.  
  46. /* Hiding the original paragraphs if they have not been replaced (JS disabled): */
  47.  
  48. .main > p{ display:none; }

滑动面板默认的打开方式是草右下方打开,你可以通过设置 openLeft 或 openTop 来改变它的打开方式。你也可以通过 class 来改变图标的颜色。
jQuery和css3滑动显示tooltips工具提示

  1. JAVASCRIPT代码:

当夜幕加载完毕,jQuery 循环整个 div 中的 p 元素,将它们替换为滑动面板标签。然后根据 style 和 class 为滑动面板绑定 click 事件:

  1. $(document).ready(function(){
  2.  /* The code here is executed on page load */
  3.  
  4.  /* Replacing all the paragraphs */
  5.  $('.main p').replaceWith(function(){
  6.  
  7.   /*
  8.    The style, class and title attributes of the p
  9.    are copied to the slideout:
  10.   */
  11.  
  12.   return '\
  13.   <div class="slideOutTip '+$(this).attr('class')+'" style="'+$(this).attr('style')+'">\
  14.    \
  15.    <div class="tipVisible">\
  16.     <div class="tipIcon"><div class="plusIcon"></div></div>\
  17.     <p class="tipTitle">'+$(this).attr('title')+'</p>\
  18.    </div>\
  19.    \
  20.    <div class="slideOutContent">\
  21.     <p>'+$(this).html()+'</p>\
  22.    </div>\
  23.   </div>';
  24.  });
  25.  
  26.  $('.slideOutTip').each(function(){
  27.  
  28.   /*
  29.    Implicitly defining the width of the slideouts according to the
  30.    width of its title, because IE fails to calculate it on its own.
  31.   */
  32.  
  33.   $(this).width(40+$(this).find('.tipTitle').width());
  34.  });
  35.  
  36.  /* Listening for the click event: */
  37.  
  38.  $('.tipVisible').bind('click',function(){
  39.   var tip = $(this).parent();
  40.  
  41.   /* If a open/close animation is in progress, exit the function */
  42.   if(tip.is(':animated'))
  43.    return false;
  44.  
  45.   if(tip.find('.slideOutContent').css('display') == 'none')
  46.   {
  47.    tip.trigger('slideOut');
  48.   }
  49.   else tip.trigger('slideIn');
  50.  
  51.  });               
  52.  $('.slideOutTip').bind('slideOut',function(){
  53.  
  54.  var tip = $(this);
  55.  var slideOut = tip.find('.slideOutContent');
  56.  
  57.  /* Closing all currently open slideouts: */
  58.  $('.slideOutTip.isOpened').trigger('slideIn');
  59.  
  60.  /* Executed only the first time the slideout is clicked: */
  61.  if(!tip.data('dataIsSet'))
  62.  {
  63.   tip .data('origWidth',tip.width())
  64.    .data('origHeight',tip.height())
  65.    .data('dataIsSet',true);
  66.  
  67.   if(tip.hasClass('openTop'))
  68.   {
  69.    /*
  70.     If this slideout opens to the top, instead of the bottom,
  71.     calculate the distance to the bottom and fix the slideout to it.
  72.    */
  73.  
  74.    tip.css({
  75.     bottom : tip.parent().height()-(tip.position().top+tip.outerHeight()),
  76.     top  : 'auto'
  77.    });
  78.  
  79.    /*
  80.     Fixing the title to the bottom of the slideout,
  81.     so it is not slid to the top on open:
  82.    */
  83.    tip.find('.tipVisible').css({position:'absolute',bottom:3});
  84.  
  85.    /*
  86.     Moving the content above the title, so it can
  87.     slide-open to the top:
  88.    */
  89.    tip.find('.slideOutContent').remove().prependTo(tip);
  90.   }
  91.  
  92.   if(tip.hasClass('openLeft'))
  93.   {
  94.    /*
  95.     If this slideout opens to the left, fix it to the right so
  96.     the left edge can expand without moving the entire div:
  97.    */
  98.    tip.css({
  99.     right : Math.abs(tip.parent().outerWidth()-(tip.position().left+tip.outerWidth())),
  100.     left : 'auto'
  101.    });
  102.  
  103.    tip.find('.tipVisible').css({position:'absolute',right:3});
  104.   }
  105.  }
  106.  
  107.  /* Resize the slideout to fit the content, which is then faded into view: */
  108.  
  109.  tip.addClass('isOpened').animate({
  110.   width : Math.max(slideOut.outerWidth(),tip.data('origWidth')),
  111.   height : slideOut.outerHeight()+tip.data('origHeight')
  112.  },function(){
  113.   slideOut.fadeIn();
  114.  });
  115.  }).bind('slideIn',function(){ // Binding the slideIn event to .slideOutTip
  116.   var tip = $(this);
  117.  
  118.   /* Hide the content and restore the original size of the slideout: */
  119.  
  120.   tip.find('.slideOutContent').fadeOut('fast',function(){
  121.    tip.animate({
  122.     width : tip.data('origWidth'),
  123.     height : tip.data('origHeight')
  124.    },function(){
  125.     tip.removeClass('isOpened');
  126.    });
  127.   });
  128.  
  129.  });
  130.  
  131. }); /* Closing $(document).ready() */

jQuery 和 css3 滑动显示 tooltips 工具提示

已有 522 人购买
查看演示升级 VIP立刻购买

下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!