jQuery UI API 类别 - 特效

Connor 抹茶今日行情 2024-06-17 64 0

jQuery UI 的特效(Effects)API 提供了一组动画效果,用于在网页上平滑地展示元素的显示、隐藏、切换等动画。这些特效增强了用户体验,使得页面元素的变化更加自然和吸引人。

以下是一个使用 jQuery UI Effects API 中 fadeIn 和 fadeOut 特效的代码示例:

html

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>jQuery UI Effects Example</title>

<!-- 引入 jQuery -->

<script src=";

<!-- 引入 jQuery UI Effects 核心库 -->

<script src=";

<style>

#toggle-button {

margin-bottom: 10px;

} heLee.net.cn/9Sw1V3G0W

wuLiust.com/6Zg2Z5K9G

daguojiangxiang.net/9Zr3N6B6B

#animated-box {

width: 200px;

height: 200px;

background-color: #4CAF50;

展开全文

color: white;

text-align: center;

line-height: 200px;

display: none; /* 初始时隐藏 */

</style>

</head>

<body>

<button id="toggle-button">Toggle Animation</button>

<div id="animated-box">Animated Box</div>

<script>

$(function() {

$('#toggle-button').click(function() {

if ($('#animated-box').is(':visible')) {

// 如果元素可见,则使用 fadeOut 特效隐藏它

$('#animated-box').fadeOut('slow');

} else {

// 如果元素不可见,则使用 fadeIn 特效显示它

$('#animated-box').fadeIn('slow');

</script>

</body>

</html>

在这个示例中,我们创建了一个按钮 #toggle-button 和一个初始时隐藏的 <div> 元素 #animated-box。当点击按钮时,我们检查 #animated-box 是否可见,如果可见则使用 fadeOut 特效将其隐藏,如果不可见则使用 fadeIn 特效将其显示。'slow' 参数表示动画的速度,jQuery UI 还支持其他速度参数,如 'fast' 或具体的毫秒数。

通过 jQuery UI 的特效 API,你可以创建更多复杂的动画效果,如 slideUp、slideDown、slideToggle、highlight、pulsate 等。这些特效不仅增强了页面的交互性,还能提高用户的参与度和满意度。

评论