zoukankan      html  css  js  c++  java
  • 底部悬浮通栏可以关闭广告位详解(一)

    效果一:

    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

  • 相关阅读:
    Django REST framework+Vue 打造生鲜超市(十二)
    pymsql
    (四)Jmeter系列之---http接口请求脚本优化
    (三)Jmeter系列之---实现一个简单的http接口请求
    2021每天一个知识点(二月)
    (二)Jmeter系列之---Jmeter工具介绍
    (一)Jmeter系列之---性能测试+工具介绍
    Linux磁盘的分区操作
    Python格式化处理json数据的方式
    (17)-Python3之--文件操作
  • 原文地址:https://www.cnblogs.com/wanghuih/p/5546441.html
Copyright © 2011-2022 走看看