用方法:
調用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 過渡允許你在 CSS 屬性值之間創建平滑的動畫效果。當一個元素的屬性值改變時,過渡效果會在一定時間內平滑地過渡到新的屬性值。
transition: property duration timing-function delay;
img:hover {
transform: scale(1.2);
transition: transform 0.3s ease-in-out;
}
這個例子中,當鼠標懸停在圖片上時,圖片會在0.3秒內放大到原來的1.2倍大小,過渡效果為ease-in-out。
CSS 動畫提供了更強大的控制,允許你創建復雜的動畫序列,通過定義關鍵幀(keyframes)來控制動畫的中間狀態。
@keyframes animation-name {
from {
/* 初始狀態 */
}
to {
/* 結束狀態 */
}
}
或者使用百分比來定義多個關鍵幀:
@keyframes animation-name {
0% { /* 初始狀態 */ }
50% { /* 中間狀態 */ }
100% { /* 結束狀態 */ }
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.icon-spin {
animation: spin 2s linear infinite;
}
這個例子創建了一個名為spin的動畫,使得圖標無限期地旋轉。
接下來,我們將通過幾個實戰例子來展示 CSS 動畫和過渡的具體應用。
.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;
}
在這個例子中,當按鈕被點擊時,會產生一個波紋效果,模擬水波紋擴散。
.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>
CSS 動畫和過渡是前端開發者的強大工具,它們可以在不犧牲性能的情況下為用戶提供流暢、引人注目的界面交互。通過掌握這些技術,你可以創造出更加動態和生動的網頁體驗。記住,動畫應該用來增強用戶體驗,而不是分散用戶的注意力,適量而恰當地使用動畫效果是關鍵。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。