整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

html提示信息框淡入淡出效果

用方法:

调用initMessagebox(“要显示的文字”)方法即可

<!--信息框-->
<div id="messagebox"></div>
<!--Load Jquery-->
 <script src="js/jquery-1.11.3.min.js"></script>
 <script>
 /*提示信息框动态效果*/
 var messageboxT;
 var top1 = 10;
 var opacity = 0;
 //初始化数据
 function initMessagebox(info) {
 top1 = 10;
 opacity = 0;
 opacity1 = 1;
 $("#messagebox").html(info);
 $("#messagebox").css({ 'display': 'block' });
 appearMessagebox();
 }
 //出现信息框
 function appearMessagebox() {
 top1 += 1;
 opacity += 0.05;
 if (opacity < 1) {
 messageboxT = setTimeout("appearMessagebox()", 15);
 }
 else {
 disappearMessagebox();
 }
 $("#messagebox").css({ 'top': String(top1) + 'px' });
 $("#messagebox").css({ 'opacity': String(opacity) });
 }
 //隐藏信息框
 function disappearMessagebox() {
 opacity -= 0.05;
 if (opacity > 0.05) {
 messageboxT = setTimeout("disappearMessagebox()", 40);
 }
 else {
 opacity = 0;
 $("#messagebox").css({ 'display': 'none' });
 }
 $("#messagebox").css({ 'opacity': String(opacity) });
 }
 </script>

用到的css

i,大家好,我是拾光;

希望大家能够关注我发布的作品。

今天的主题就是【CSS文本底部淡入淡出效果】

下面是效果图:

说明:由于图中文章篇幅比较长,所以大家可以略过文章的内容,直接看代码;

排版可能不是特别好,希望大家能够理解。

HTML:

<!DOCTYPE html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>css文本底部淡入淡出效果 - 站长素材</title>

<link rel="stylesheet" type="text/css" href="style.css" />

<!--[if lte IE 6]>

<style type="text/css" media="screen">

#bottom_fade {

background: none;

filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='bottom-fade.png',sizingMethod='scale');

left: 0px;

height: 200px;

position: absolute;

bottom: -18px;

width: expression(document.body.clientWidth);

}

html, body {

height: 100%; overflow: auto;

}

</style>

<![endif]-->

</head>

<body>

<div id="page_wrap">

<div>

Completely revolutionize high-quality niches after mission-critical expertise. Professionally deploy standardized total linkage before interoperable architectures. Quickly formulate future-proof meta-services through cross functional portals. Holisticly procrastinate timely results vis-a-vis principle-centered human capital. Distinctively incubate emerging systems and collaborative best practices. Compellingly exploit next-generation technology via web-enabled results.

</div>

</div>

<div>

Professionally disintermediate 24/365 web services via intermandated technologies. Holisticly disseminate flexible web services through professional results. Enthusiastically empower integrated channels and standards compliant channels. Proactively brand end-to-end process improvements rather than resource sucking results. Phosfluorescently envisioneer excellent growth strategies rather than equity invested outsourcing. Assertively build progressive data whereas process-centric processes. Dramatically visualize highly efficient sources via accurate applications. Efficiently engineer orthogonal infomediaries for cross functional ROI. Conveniently restore alternative functionalities after intermandated systems.

</div>

<div>

Credibly aggregate dynamic synergy and one-to-one testing procedures. Credibly synergize out-of-the-box growth strategies via timely mindshare. Synergistically embrace extensive schemas and multidisciplinary processes. Monotonectally synergize 2.0 sources before resource-leveling sources. Professionally grow value-added results before client-based internal or "organic" sources. Uniquely network alternative processes for interoperable solutions.

</div>

<div>

Quickly fabricate out-of-the-box relationships via top-line e-services. Uniquely restore market positioning synergy rather than long-term high-impact manufactured products. Monotonectally plagiarize high-payoff interfaces rather than business internal or "organic" sources. Credibly synergize plug-and-play interfaces rather than intuitive results. Compellingly expedite fully tested outsourcing vis-a-vis impactful synergy. Energistically build strategic value and excellent portals. Holisticly deliver revolutionary users before extensive value. Uniquely leverage other's low-risk high-yield e-services before multidisciplinary action items. Dynamically formulate proactive metrics via just in time e-business.

</div>

<div>

Objectively parallel task 24/365 services after superior products. Competently disintermediate unique web services through unique outsourcing. Efficiently evisculate functionalized data with market positioning resources.

</div>

<div>

Distinctively reconceptualize principle-centered niches rather than state of the art action items. Compellingly disseminate 24/365 convergence and standardized architectures. Continually repurpose high-payoff methods of empowerment whereas virtual relationships. Compellingly administrate professional web-readiness before worldwide bandwidth. Energistically redefine high-payoff bandwidth for empowered niches. Phosfluorescently foster backward-compatible e-tailers for backward-compatible architectures.

</div>

<div>

Distinctively re-engineer impactful architectures and resource sucking niches. Authoritatively envisioneer leveraged total linkage whereas vertical value. Phosfluorescently iterate dynamic opportunities through multimedia based systems. Uniquely e-enable frictionless paradigms after B2C initiatives. Credibly deliver go forward methods of empowerment via professional total linkage. Dramatically deliver client-based portals whereas collaborative innovation. Uniquely parallel task quality opportunities before highly efficient e-tailers. Synergistically productivate world-class infomediaries and distributed content. Appropriately build equity invested e-commerce and focused process improvements. Efficiently architect holistic methods of empowerment for reliable customer service. Phosfluorescently utilize synergistic mindshare with adaptive methodologies. Seamlessly strategize best-of-breed niche markets without high-quality materials.

</div>

<div>

Conveniently develop alternative total linkage via customized testing procedures. Credibly scale timely relationships whereas front-end vortals. Quickly target cost effective e-business through strategic services. Uniquely seize installed base deliverables through user-centric niche markets. Seamlessly simplify top-line strategic theme areas through corporate outsourcing. Appropriately incubate frictionless markets whereas functionalized web services.

</div>

<div>Assertively synthesize revolutionary technologies after competitive value.</div>

<div id="bottom_fade"></div>

</div>

<div style="text-align:center;clear:both">

</div>

</body>

</html>

CSS:

* {

margin: 0;

padding: 0;

border: 0;

}

body {

font-family: "Lucida Grande", Georgia, sans-serif;

font-size: 67.5%;

}

p {

font-size: 1.1em;

line-height: 1.6em;

}

#page_wrap {

width: 600px;

z-index: 1;

margin: 10px auto;

}

#bottom_fade {

width: 600px;

height: 200px;

z-index: 99;

position: fixed;

bottom: 0px;

background: url("bottom-fade.png") bottom center no-repeat;

}

素材在此,大家可以【使用电脑】点击图片另存为进行保存。

今天的任务就到这里了,希望大家多多支持。

现代网页设计中,动画和过渡是提升用户体验的重要手段。通过使用 CSS,我们可以在不影响页面性能的前提下,实现平滑和吸引人的视觉效果。本文将介绍 CSS 动画和过渡的基础知识,并通过几个例子展示如何在你的网站中应用它们。

CSS 过渡(Transitions)

CSS 过渡允许你在 CSS 属性值之间创建平滑的动画效果。当一个元素的属性值改变时,过渡效果会在一定时间内平滑地过渡到新的属性值。

基本语法

transition: property duration timing-function delay;
  • property:指定要添加过渡效果的 CSS 属性。
  • duration:过渡效果的持续时间。
  • timing-function:定义速度曲线的函数。
  • delay:过渡效果的延迟时间。

例子 1:鼠标悬停放大图片

img:hover {
  transform: scale(1.2);
  transition: transform 0.3s ease-in-out;
}

这个例子中,当鼠标悬停在图片上时,图片会在0.3秒内放大到原来的1.2倍大小,过渡效果为ease-in-out。

CSS 动画(Animations)

CSS 动画提供了更强大的控制,允许你创建复杂的动画序列,通过定义关键帧(keyframes)来控制动画的中间状态。

基本语法

@keyframes animation-name {
  from {
    /* 初始状态 */
  }
  to {
    /* 结束状态 */
  }
}

或者使用百分比来定义多个关键帧:

@keyframes animation-name {
  0% { /* 初始状态 */ }
  50% { /* 中间状态 */ }
  100% { /* 结束状态 */ }
}

例子 2:无限旋转图标

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.icon-spin {
  animation: spin 2s linear infinite;
}

这个例子创建了一个名为spin的动画,使得图标无限期地旋转。

实战例子

接下来,我们将通过几个实战例子来展示 CSS 动画和过渡的具体应用。

例子 3:按钮点击波纹效果

.button {
  position: relative;
  overflow: hidden;
  transition: background-color 0.3s;
}

.button:after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 5px;
  height: 5px;
  background: rgba(255, 255, 255, 0.7);
  opacity: 0;
  border-radius: 100%;
  transform: scale(1, 1) translate(-50%);
  transform-origin: 50% 50%;
}

.button:active:after {
  width: 300px;
  height: 300px;
  opacity: 1;
  transition: width 0.5s, height 0.5s, opacity 0s 0.5s;
}

在这个例子中,当按钮被点击时,会产生一个波纹效果,模拟水波纹扩散。

例子 4:淡入淡出切换效果

.fade-in {
  animation: fadeIn 1s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.fade-out {
  animation: fadeOut 1s ease-in-out;
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

这个例子中定义了两个动画,一个用于元素的淡入,另一个用于元素的淡出。

示例

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Animation and Transition Example</title>
<style>
  body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    min-height: 100vh;
  }

  @keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
  }

  .logo {
    font-size: 2em;
    color: #007bff;
    margin-bottom: 20px;
    animation: spin 3s linear infinite;
  }

  .scrolling-text {
    margin: 20px 0;
    background-color: #333;
    color: #fff;
    padding: 10px;
    white-space: nowrap;
    overflow: hidden;
    position: relative;
  }

  .scrolling-text p {
    position: absolute;
    width: 100%;
    height: 100%;
    margin: 0;
    line-height: 50px;
    text-align: center;
    /* Starting position */
    transform: translateX(100%);
    /* Apply animation to this element */
    animation: scroll-text 10s linear infinite;
  }

  @keyframes scroll-text {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
  }

  .interactive-card {
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    padding: 20px;
    margin: 20px;
    border-radius: 10px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
  }

  .interactive-card:hover {
    transform: translateY(-10px);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  }

  .color-block {
    width: 100px;
    height: 100px;
    background-color: #17a2b8;
    margin: 20px;
    border-radius: 50%;
    transition: background-color 0.5s ease, transform 0.5s ease;
  }

  .color-block:hover {
    background-color: #28a745;
    transform: rotate(180deg);
  }
</style>
</head>
<body>

<div class="logo">
  <i class="fas fa-sync-alt"></i> Animated Logo
</div>

<div class="scrolling-text">
  <p>This text scrolls infinitely. Pay attention to how it moves smoothly from right to left.</p>
</div>

<div class="interactive-card">
  <h3>Interactive Card</h3>
  <p>Hover over this card to see it move. It's a simple yet effective way to add interactivity to your design.</p>
</div>

<div class="color-block"></div>

</body>
</html>

  • .logo 类定义了一个徽标,它具有字体大小和颜色,并应用了一个名为 spin 的关键帧动画,使徽标无限旋转。
  • .scrolling-text 类定义了一个包含滚动文本的容器,设置了背景颜色、文字颜色和内边距。
  • .scrolling-text p 选择器定义了滚动文本的样式,包括动画 scroll-text,使文本从右向左无限滚动。
  • .interactive-card 类定义了一个交互式卡片,它具有背景颜色、阴影、内边距和圆角。当鼠标悬停时,它会向上移动并增加阴影,这是通过 transition 属性实现的。
  • .color-block 类定义了一个颜色块,设置了宽度、高度、背景颜色和圆角。当鼠标悬停时,它的背景颜色会改变,并且会旋转 180 度。
  • body 的背景被设置为一个线性渐变,包含四种颜色。通过 background-size 属性,我们扩大了背景尺寸,这样动画在运行时会有更多的空间进行颜色的过渡。
  • @keyframes gradientBG 关键帧动画被创建来改变背景的位置,从而在不同的颜色之间产生平滑过渡的效果。
  • 该动画被设置为无限循环,并且每次循环持续 15 秒,通过 ease 时间函数来平滑过渡。

结语

CSS 动画和过渡是前端开发者的强大工具,它们可以在不牺牲性能的情况下为用户提供流畅、引人注目的界面交互。通过掌握这些技术,你可以创造出更加动态和生动的网页体验。记住,动画应该用来增强用户体验,而不是分散用户的注意力,适量而恰当地使用动画效果是关键。