底部悬浮通栏可以关闭广告位详解(一)
效果一:
1.首先,整个底部悬浮通栏广告是固定在浏览器的底部,随着浏览器的滚动,底部悬浮广告始终在浏览器窗口中。这里有几个关键点:通栏,固定,黑色。
所以:首先我们必须给悬浮通栏广告整体一个100%的宽度,其次给它设定固定定位,固定在浏览器底部,背景色为黑色,透明度为0.7。
<span style="color: #008080;">1</span> <span style="color: #800000;">.footfixed</span>{ <span style="color: #008080;">2</span> <span style="color: #ff0000;">width</span>:<span style="color: #0000ff;">100%</span>; <span style="color: #008080;">3</span> <span style="color: #ff0000;">height</span>:<span style="color: #0000ff;">140px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> 图片大小,宽度必须100% </span><span style="color: #008000;">*/</span> <span style="color: #008080;">4</span> <span style="color: #ff0000;">position</span>:<span style="color: #0000ff;">fixed</span>; <span style="color: #008080;">5</span> <span style="color: #ff0000;">bottom</span>:<span style="color: #0000ff;">0</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">固定定位,固定在浏览器底部。</span><span style="color: #008000;">*/</span> <span style="color: #008080;">6</span> <span style="color: #ff0000;">background</span>:<span style="color: #0000ff;"> #081628</span>; <span style="color: #008080;">7</span> <span style="color: #ff0000;">opacity</span>:<span style="color: #0000ff;"> .7</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">Chrome、Safari、Firefox、Opera </span><span style="color: #008000;">*/</span><span style="color: #ff0000;"> <br> filter</span>:<span style="color: #0000ff;">alpha(opacity=70)</span>;<span style="color: #008000;">/*</span><span style="color: #008000;"> 针对 IE8 以及更早的版本 </span><span style="color: #008000;">*/</span> <span style="color: #008080;">8</span> }
2. 底部悬浮通栏广告的图片,可以看出比背景要高(背景height:140px,内图height: 218px)
且整体内容部分居中。
<span style="color: #008080;">1</span> <span style="color: #800000;">.fimg </span>{ <span style="color: #008080;">2</span> <span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 218px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">注意此处图片高度高于140px</span><span style="color: #008000;">*/</span> <span style="color: #008080;">3</span> <span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 1190px</span>; <span style="color: #008080;">4</span> <span style="color: #ff0000;"> margin</span>:<span style="color: #0000ff;"> 0px auto</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">整体内容部分居中</span><span style="color: #008000;">*/</span> <span style="color: #008080;">5</span> }
然而由于底部悬浮广告内容部分高度218px大于设定的父元素的高度140px,高度相差78px
产生如下效果,图片没能完成的展现出来:
这需要图片上移78px,需要对整个底部悬浮广告内容部分整体做相对定位
<span style="color: #008080;">1</span> <span style="color: #800000;">.fimg </span>{ <span style="color: #008080;">2</span> <span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;"> relative</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">父元素相对定位</span><span style="color: #008000;">*/</span> <span style="color: #008080;">3</span> <span style="color: #ff0000;"> top</span>:<span style="color: #0000ff;">-78px</span>; <span style="color: #008080;">4</span> }
结果:
这里有个问题:
图片不是很清楚,因为加了透明度。
解决这个问题,用一个div来设置背景,而不在.footfixed里设置背景色。
1 div class="ftbj">div>
<span style="color: #008080;"> 1</span> <span style="color: #800000;">.ftbj</span>{ <span style="color: #008080;"> 2</span> <span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;">100%</span>; <span style="color: #008080;"> 3</span> <span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;">100%</span>; <span style="color: #008080;"> 4</span> <span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;"> absolute</span>; <span style="color: #008080;"> 5</span> <span style="color: #ff0000;"> top</span>:<span style="color: #0000ff;"> 0</span>; <span style="color: #008080;"> 6</span> <span style="color: #ff0000;"> left</span>:<span style="color: #0000ff;"> 0</span>; <span style="color: #008080;"> 7</span> <span style="color: #ff0000;"> background</span>:<span style="color: #0000ff;">#081628</span>; <span style="color: #008080;"> 8</span> <span style="color: #ff0000;"> opacity</span>:<span style="color: #0000ff;"> .7</span>;<span style="color: #008000;">/*</span><span style="color: #008000;">Chrome、Safari、Firefox、Opera </span><span style="color: #008000;">*/</span><span style="color: #008080;"> <br> 9</span> <span style="color: #ff0000;"> filter</span>:<span style="color: #0000ff;"> alpha(opacity=70)</span>;}<span style="color: #008000;">/*</span><span style="color: #008000;"> 针对 IE8 以及更早的版本 </span><span style="color: #008000;">*/</span> <span style="color: #008080;">10</span> <span style="color: #800000;">.footfixed</span>{ <span style="color: #008080;">11</span> <span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;">100%</span>; <span style="color: #008080;">12</span> <span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;">140px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> 图片大小,宽度必须100% </span><span style="color: #008000;">*/</span> <span style="color: #008080;">13</span> <span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;">fixed</span>; <span style="color: #008080;">14</span> <span style="color: #ff0000;"> bottom</span>:<span style="color: #0000ff;">0</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">固定定位,固定在浏览器底部。</span><span style="color: #008000;">*/</span> <span style="color: #008080;">15</span> }
这样图片效果:
这样就清楚多了。
3.其中关闭按钮的效果:
首先按钮是由图片通过定位实现固定在整个底部悬浮广告图片右上角。需设定图片大小,图片引入路径,需要对整个底部悬浮广告内容部分整体做相对定位,关闭按钮是做绝对定位
<span style="color: #008080;"> 1</span> <span style="color: #800000;">.fimg </span>{ <span style="color: #008080;"> 2</span> <span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;"> relative</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">父元素相对定位</span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 3</span> } <span style="color: #008080;"> 4</span> <span style="color: #800000;">.close </span>{ <span style="color: #008080;"> 5</span> <span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 33px</span>; <span style="color: #008080;"> 6</span> <span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 33px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> 图片大小 </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 7</span> <span style="color: #ff0000;"> background</span>:<span style="color: #0000ff;"> url(images/close.png) no-repeat center center</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">图片引入路径 </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 8</span> <span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;"> absolute</span>; <span style="color: #008080;"> 9</span> <span style="color: #ff0000;"> right</span>:<span style="color: #0000ff;"> 15px</span>; <span style="color: #008080;">10</span> <span style="color: #ff0000;"> top</span>:<span style="color: #0000ff;"> 85px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">通过定位实现固定固定在整个底部悬浮广告图片右上角 </span><span style="color: #008000;">*/</span> <span style="color: #008080;">11</span> }
其次,鼠标移到关闭按钮上,有小手出现,关闭按钮旋转。
为了产生动画效果,加transition
<span style="color: #008080;"> 1</span> <span style="color: #800000;">.close </span>{ <span style="color: #008080;"> 2</span> <span style="color: #ff0000;"> transition</span>:<span style="color: #0000ff;"> .5s</span>; <span style="color: #008080;"> 3</span> <span style="color: #ff0000;"> cursor</span>:<span style="color: #0000ff;"> pointer</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">通过定位实现固定固定在整个底部悬浮广告图片右上角 </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 4</span> } <span style="color: #008080;"> 5</span> <span style="color: #800000;">.close:hover </span>{ <span style="color: #008080;"> 6</span> <span style="color: #ff0000;"> transform</span>:<span style="color: #0000ff;"> rotate(180deg)</span>; <span style="color: #008080;"> 7</span> <span style="color: #ff0000;"> -ms-transform</span>:<span style="color: #0000ff;"> rotate(180deg)</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> IE 9 </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 8</span> <span style="color: #ff0000;"> -moz-transform</span>:<span style="color: #0000ff;"> rotate(180deg)</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> Firefox </span><span style="color: #008000;">*/</span> <span style="color: #008080;"> 9</span> <span style="color: #ff0000;"> -webkit-transform</span>:<span style="color: #0000ff;"> rotate(180deg)</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> Safari 和 Chrome </span><span style="color: #008000;">*/</span> <span style="color: #008080;">10</span> <span style="color: #ff0000;"> -o-transform</span>:<span style="color: #0000ff;"> rotate(180deg)</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> Opera </span><span style="color: #008000;">*/</span> <span style="color: #008080;">11</span> } <span style="color: #008000;">/*</span><span style="color: #008000;">旋转 图片</span>*/
然后是点击关闭按钮,广告向下消失,侧边出现效果
<span style="color: #008080;">1</span> <span style="color: #800000;">#fimg-min</span>{ <span style="color: #008080;">2</span> <span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 80px</span>; <span style="color: #008080;">3</span> <span style="color: #ff0000;"> height</span>:<span style="color: #0000ff;"> 140px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;"> 图片大小 </span><span style="color: #008000;">*/</span> <span style="color: #008080;">4</span> <span style="color: #ff0000;"> position</span>:<span style="color: #0000ff;"> fixed</span>; <span style="color: #008080;">5</span> <span style="color: #ff0000;"> bottom</span>:<span style="color: #0000ff;"> 0px</span>; <span style="color: #008080;">6</span> <span style="color: #ff0000;"> left</span>:<span style="color: #0000ff;"> 0px</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">定位</span><span style="color: #008000;">*/</span> <span style="color: #008080;">7</span> <span style="color: #ff0000;"> display</span>:<span style="color: #0000ff;"> none</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">隐藏</span><span style="color: #008000;">*/</span> <span style="color: #008080;">8</span> <span style="color: #ff0000;"> cursor</span>:<span style="color: #0000ff;"> pointer</span>; <span style="color: #008000;">/*</span><span style="color: #008000;">小手 </span><span style="color: #008000;">*/</span> <span style="color: #008080;">9</span> }
点击图中圈出来的图标,底部广告再次出现
<span style="color: #008080;"> 1</span> <script> <span style="color: #008080;"> 2 $(document).ready(<span style="color: #0000ff;">function<span style="color: #000000;">(){ <span style="color: #008080;"> 3 $(".close").click(<span style="color: #0000ff;">function<span style="color: #000000;"> () { <span style="color: #008080;"> 4 $('.footfixed'<span style="color: #000000;">).animate( <span style="color: #008080;"> 5 {height: '10px', opacity: '0.4'}, "slow", <span style="color: #0000ff;">function<span style="color: #000000;"> () { <span style="color: #008080;"> 6 $('.footfixed'<span style="color: #000000;">).hide(); <span style="color: #008080;"> 7 $('#fimg-min'<span style="color: #000000;">).show(); <span style="color: #008080;"> 8 <span style="color: #000000;"> }); <span style="color: #008080;"> 9 <span style="color: #000000;"> }); <span style="color: #008080;">10 $('#fimg-min').click(<span style="color: #0000ff;">function<span style="color: #000000;">(){ <span style="color: #008080;">11 $('.footfixed').show().css({height:'140px',opacity:'1'<span style="color: #000000;">}); <span style="color: #008080;">12 $('#fimg-min'<span style="color: #000000;">).hide(); <span style="color: #008080;">13 <span style="color: #000000;"> }); <span style="color: #008080;">14 <span style="color: #000000;">}); <span style="color: #008080;">15 </script> <span style="color: #008080;">16</span>
注:在ie9以下浏览器中关闭按钮图片旋转效果未能实现。
注意:本文为原创,转载请以链接形式标明本文地址 ,谢谢合作。
本文地址:http://www.cnblogs.com/wanghuih/p/5546441.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTML is suitable for beginners because it is simple and easy to learn and can quickly see results. 1) The learning curve of HTML is smooth and easy to get started. 2) Just master the basic tags to start creating web pages. 3) High flexibility and can be used in combination with CSS and JavaScript. 4) Rich learning resources and modern tools support the learning process.

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

AnexampleofastartingtaginHTMLis,whichbeginsaparagraph.StartingtagsareessentialinHTMLastheyinitiateelements,definetheirtypes,andarecrucialforstructuringwebpagesandconstructingtheDOM.

To achieve the effect of scattering and enlarging the surrounding images after clicking on the image, many web designs need to achieve an interactive effect: click on a certain image to make the surrounding...

HTML, CSS and JavaScript are the three pillars of web development. 1. HTML defines the web page structure and uses tags such as, etc. 2. CSS controls the web page style, using selectors and attributes such as color, font-size, etc. 3. JavaScript realizes dynamic effects and interaction, through event monitoring and DOM operations.

The Y-axis position adaptive algorithm for web annotation function This article will explore how to implement annotation functions similar to Word documents, especially how to deal with the interval between annotations...
