效果一:
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 */
filter:alpha(opacity=70);/* 针对 IE8 以及更早的版本 */8 }
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 }
结果:
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 }
点击图中圈出来的图标,底部广告再次出现
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:0.7});12 $('#fimg-min').hide();13 }); 14 });15 </script>16
注:在ie9以下浏览器中关闭按钮图片旋转效果未能实现。
原标题:底部悬浮通栏可以关闭广告位详解(一)
关键词: