底部懸浮通欄可以關閉廣告位詳解(一)


效果一:

1.首先,整個底部懸浮通欄廣告是固定在瀏覽器的底部,隨着瀏覽器的滾動,底部懸浮廣告始終在瀏覽器窗口中。這里有幾個關鍵點:通欄,固定,黑色。

所以:首先我們必須給懸浮通欄廣告整體一個100%的寬度,其次給它設定固定定位,固定在瀏覽器底部,背景色為黑色,透明度為0.7。

 1 .footfixed{
 2    width:100%; 
 3    height:140px;     /* 圖片大小,寬度必須100% */
 4   position:fixed;
 5   bottom:0;         /*固定定位,固定在瀏覽器底部。*/
 6   background: #081628;
 7   opacity: .7;    /*Chrome、Safari、Firefox、Opera */ 
 8    filter:alpha(opacity=70);/* 針對 IE8 以及更早的版本 */
 9     z-index: 99999;
10  }

2. 底部懸浮通欄廣告的圖片,可以看出比背景要高(背景height:140px,內圖height: 218px)

且整體內容部分居中。

1 .fimg {
2     height: 218px;        /*注意此處圖片高度高於140px*/
3     width: 1190px; 
4     margin: 0px auto;    /*整體內容部分居中*/
5 }

然而由於底部懸浮廣告內容部分高度218px大於設定的父元素的高度140px,高度相差78px

產生如下效果,圖片沒能完成的展現出來:

我的隨筆 - 我的前端之路 - 博客園

這需要圖片上移78px,需要對整個底部懸浮廣告內容部分整體做相對定位

1 .fimg {
2     position: relative;    /*父元素相對定位*/
3     top:-78px;
4 }

結果:

我的隨筆 - 我的前端之路 - 博客園

這里有個問題:

圖片不是很清楚,因為加了透明度。

解決這個問題,用一個div來設置背景,而不在.footfix 里設置背景

1 <div class="ftbj"></div> 

 1 .ftbj{
 2       height:100%;
 3       width:100%;
 4       position: absolute;
 5       top: 0;
 6       left: 0;    
 7       background:#081628;
 8       opacity: .7;/*Chrome、Safari、Firefox、Opera */ 
 9       filter: alpha(opacity=70);}/* 針對 IE8 以及更早的版本 */
10 }
11  .footfixed{
12       width:100%; 
13       height:140px; /* 圖片大小,寬度必須100% */ 
14       position:fixed; 
15       bottom:0; /*固定定位,固定在瀏覽器底部。*/
16       z-index: 99999;
17  }

這樣圖片效果:

我的隨筆 - 我的前端之路 - 博客園

這樣就清楚多了。

3.其中關閉按鈕的效果:

首先按鈕是由圖片通過定位實現固定在整個底部懸浮廣告圖片右上角。需設定圖片大小,圖片引入路徑,需要對整個底部懸浮廣告內容部分整體做相對定位,關閉按鈕是做絕對定位

 1 .fimg {
 2     position: relative;    /*父元素相對定位*/
 3 }
 4 .close {
 5     width: 33px;
 6     height: 33px;         /* 圖片大小 */
 7     background: url(images/close.png) no-repeat center center;    /*圖片引入路徑 */
 8     position: absolute;
 9     right: 15px;
10     top: 85px;             /*通過定位實現固定固定在整個底部懸浮廣告圖片右上角 */
11 }

其次,鼠標移到關閉按鈕上,有小手出現,關閉按鈕旋轉。

為了產生動畫效果,加transition

 1  .close {
 2      transition: .5s;
 3      cursor: pointer;   /*小手 */
 4 } 
 5  .close:hover { 
 6      transform: rotate(180deg);  
 7      -ms-transform: rotate(180deg);     /* IE 9 */
 8      -moz-transform: rotate(180deg);    /* Firefox */
 9      -webkit-transform: rotate(180deg);    /* Safari 和 Chrome */ 
10      -o-transform: rotate(180deg);       /* Opera */
11 } /*旋轉 圖片*/
 
        

 

然后是點擊關閉按鈕,廣告向下消失,側邊出現效果

我的隨筆 - 我的前端之路 - 博客園

 1 #fimg-min{
 2      width: 80px;
 3      height: 140px;                     /* 圖片大小 */
 4      position: fixed; 
 5      bottom: 0px; 
 6      left: 0px;                         /*定位*/    
 7      display: none;                    /*隱藏*/
 8      cursor: pointer;                /*小手 */
 9      z-index: 99999;
10 }

 

點擊圖中圈出來的圖標,底部廣告再次出現

 1 <script>
 2 $(document).ready(function(){
 3     $(".close").click(function () {
 4         $('.footfixed').animate(
 5             {height: '10px', opacity: '0.4'}, "slow", function () {
 6         $('.footfixed').hide();
 7         $('#fimg-min').show();
 8         });
 9     });    
10     $('#fimg-min').click(function(){
11             $('.footfixed').show().css({height:'140px',opacity:'1'});
12             $('#fimg-min').hide();
13     });    
14 });
15 </script>
16          

注:在ie9以下瀏覽器中關閉按鈕圖片旋轉效果未能實現。

注意:本文為原創,轉載請以鏈接形式標明本文地址 ,謝謝合作。
本文地址:http://www.cnblogs.com/wanghuih/p/5546441.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM