CSS3實現Tooltip提示框飛入飛出動畫

咱們見過不少利用背景圖片製做的Tooltip提示框,可是缺點是擴展比較麻煩,要常常改動圖片。還有就是利用多層CSS的疊加實現,可是效果比較生硬,外觀不怎麼好看。今天我來分享一下利用CSS3快速實現既美觀又實用的Tooltip提示框,提示框伴有飛入飛出的動畫效果。先來看看效果圖。css

看上去還簡單吧,其實實現的思路的確很簡單。html

具體效果咱們能夠在這裏查看在線演示html5

接下來咱們來簡單分析一下這個Tooltip實現的CSS3代碼。css3

首先是HTML代碼,主要是構造了3個小圖標菜單以及對應的Tooltip提示框內容:web

<div id="container">
<div class="item">

      <h1>D</h1>
<div class="tooltip">
  <p>Find important documents and manuals.</p>
  <div class="arrow"></div>
  </div>
  </div>
</div>

  <div class="item">
      <h1>A</h1>

    <div class="tooltip">
  <p>Take a look at our crew and become a friend.</p>
  <div class="arrow"></div>
  </div>
  </div>
</div>

  <div class="item">
      <h1>C</h1>
    <div class="tooltip">
  <p>Explore our process and see how we can help.</p>
  <div class="arrow"></div>
  </div>
  </div>

接下來是CSS代碼,首先咱們定義了一個圖標集,讓每一個小按鈕都能顯示各自的圖標:dom

@font-face {
    font-family:'HeydingsCommonIconsRegular';
    src: url('http://ianfarb.com/random/heydings_icons-webfont.eot');
    src: url('http://ianfarb.com/random/heydings_icons-webfont.eot?#iefix') format('embedded-opentype'),
         url('http://ianfarb.com/random/heydings_icons-webfont.woff') format('woff'),
         url('http://ianfarb.com/random/heydings_icons-webfont.ttf') format('truetype'),
         url('http://ianfarb.com/random/heydings_icons-webfont.svg#HeydingsCommonIconsRegular') format('svg');
    font-weight: normal;
    font-style: normal;

}
h1    {font-family:'HeydingsCommonIconsRegular', sans-serif;
       font-weight:normal;
       margin:30px 0 0 0;
       color:#fff;
  text-align:center;
       font-size:60px;
       line-height:30px;}

而後重點是實現Tooltip提示框:svg

.tooltip { width:120px;
           padding:10px;
           border-radius:3px;
           position:absolute;
           box-shadow:1px 1px 10px 0 #ccc;
           margin: -500px 0 0 -20px;
           background:#fff;
           -webkit-transition:margin .5s ease-in-out;
          -moz-transition:margin .5s ease-in-out;}

.item:hover  {  background:#6d643b;}

.item:hover .tooltip {
           margin:-145px 0 0 -20px;
           -webkit-transition: margin .15s ease-in-out;
  -moz-transition: margin .15s ease-in-out;}

.arrow {
  position:absolute;
  margin:10px 0 0 50px;
    width: 0; 
    height: 0; 
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid #fff;
}

這裏咱們對Tooltip區域進行了圓角和陰影的效果渲染,讓其在鼠標滑過是飛入,鼠標移出是飛出,看得出來,實現這樣的效果主要仍是利用了動畫

-webkit-transition和-moz-transition

最後是一個向下的小箭頭,用類.arrow來標識,上面的代碼也實現了這個CSS的實現。url

最後,提供一個源代碼包給你們,下載地址>>spa

相關文章
相關標籤/搜索