Maison interface Web tutoriel HTML 底部悬浮通栏可以关闭广告位详解(一)

底部悬浮通栏可以关闭广告位详解(一)

Jun 01, 2016 pm 02:32 PM

效果一:

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> }
Copier après la connexion

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> }
Copier après la connexion

然而由于底部悬浮广告内容部分高度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> }
Copier après la connexion

结果:

这里有个问题:

图片不是很清楚,因为加了透明度。

解决这个问题,用一个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> }
Copier après la connexion

这样图片效果:

这样就清楚多了。

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> }
Copier après la connexion

其次,鼠标移到关闭按钮上,有小手出现,关闭按钮旋转。

为了产生动画效果,加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>*/
Copier après la connexion
Copier après la connexion

然后是点击关闭按钮,广告向下消失,侧边出现效果

<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> }
Copier après la connexion

点击图中圈出来的图标,底部广告再次出现

<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>          
Copier après la connexion

注:在ie9以下浏览器中关闭按钮图片旋转效果未能实现。

注意:本文为原创,转载请以链接形式标明本文地址 ,谢谢合作。
本文地址:http://www.cnblogs.com/wanghuih/p/5546441.html

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

Video Face Swap

Video Face Swap

Échangez les visages dans n'importe quelle vidéo sans effort grâce à notre outil d'échange de visage AI entièrement gratuit !

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)

HTML est-il facile à apprendre pour les débutants? HTML est-il facile à apprendre pour les débutants? Apr 07, 2025 am 12:11 AM

HTML convient aux débutants car il est simple et facile à apprendre et peut rapidement voir les résultats. 1) La courbe d'apprentissage de HTML est fluide et facile à démarrer. 2) Il suffit de maîtriser les balises de base pour commencer à créer des pages Web. 3) Flexibilité élevée et peut être utilisée en combinaison avec CSS et JavaScript. 4) Les ressources d'apprentissage riches et les outils modernes soutiennent le processus d'apprentissage.

Les rôles de HTML, CSS et JavaScript: responsabilités de base Les rôles de HTML, CSS et JavaScript: responsabilités de base Apr 08, 2025 pm 07:05 PM

HTML définit la structure Web, CSS est responsable du style et de la mise en page, et JavaScript donne une interaction dynamique. Les trois exercent leurs fonctions dans le développement Web et construisent conjointement un site Web coloré.

Quel est un exemple d'une balise de départ dans HTML? Quel est un exemple d'une balise de départ dans HTML? Apr 06, 2025 am 12:04 AM

Anexampleofastartingtaginhtmlis, qui abinginsaparagraph.startingtagsaressentialtinhtmlastheyinitiateelements, définit les éventualités, et la faculté de réduction des pages et de la construction de la création.

Comprendre HTML, CSS et JavaScript: un guide pour débutant Comprendre HTML, CSS et JavaScript: un guide pour débutant Apr 12, 2025 am 12:02 AM

WebDevelopmentReliesOnHTML, CSS, etjavascript: 1) HTMLSTRUCTURESCONTENT, 2) CSSSTYLESIT, et3) JavascriptAdddsInterActivity, Forming TheasisofmodernweBEBExperiences.

Gitee Pages STATIQUE Le déploiement du site Web a échoué: comment dépanner et résoudre les erreurs de fichier unique 404? Gitee Pages STATIQUE Le déploiement du site Web a échoué: comment dépanner et résoudre les erreurs de fichier unique 404? Apr 04, 2025 pm 11:54 PM

GiteEpages STATIQUE Le déploiement du site Web a échoué: 404 Dépannage des erreurs et résolution lors de l'utilisation de Gitee ...

Comment implémenter la disposition adaptative de la position de l'axe y dans l'annotation Web? Comment implémenter la disposition adaptative de la position de l'axe y dans l'annotation Web? Apr 04, 2025 pm 11:30 PM

L'algorithme adaptatif de la position de l'axe y pour la fonction d'annotation Web Cet article explorera comment implémenter des fonctions d'annotation similaires aux documents de mots, en particulier comment gérer l'intervalle entre les annotations ...

Comment utiliser CSS3 et JavaScript pour réaliser l'effet de la diffusion et de l'agrandissement des images environnantes après avoir cliqué? Comment utiliser CSS3 et JavaScript pour réaliser l'effet de la diffusion et de l'agrandissement des images environnantes après avoir cliqué? Apr 05, 2025 am 06:15 AM

Pour obtenir l'effet de la diffusion et de l'élargissement des images environnantes après avoir cliqué sur l'image, de nombreuses conceptions Web doivent obtenir un effet interactif: cliquez sur une certaine image pour faire les environs ...

Pourquoi avez-vous besoin d'appeler Vue.User (VUerouter) dans le fichier index.js dans le dossier du routeur? Pourquoi avez-vous besoin d'appeler Vue.User (VUerouter) dans le fichier index.js dans le dossier du routeur? Apr 05, 2025 pm 01:03 PM

La nécessité d'enregistrer VUerouter dans le fichier index.js dans le dossier du routeur Lors du développement d'applications VUE, vous rencontrez souvent des problèmes de configuration de routage. Spécial...

See all articles