jquery特效代码
当涉及到jQuery特效代码时,具体的代码取决于你想要实现的效果。淡入淡出效果:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Fade Effect</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<style>
.box {
width: 200px;
height: 200px;
background-color: lightblue;
display: none;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
$(document).ready(function(){
$(".box").fadeIn(1000); // 1000毫秒淡入效果
});
</script>
</body>
</html>
滑动效果:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Slide Effect</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<style>
.box {
width: 200px;
height: 200px;
background-color: lightblue;
display: none;
}
</style>
</head>
<body>
<div class="box"></div>
<script>
$(document).ready(function(){
$(".box").slideDown(1000); // 1000毫秒滑动效果
});
</script>
</body>
</html>
点击切换效果:
html<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jQuery Toggle Effect</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<style>
.box {
width: 200px;
height: 200px;
background-color: lightblue;
display: none;
}
</style>
</head>
<body>
<button id="toggleButton">Toggle Box</button>
<div class="box"></div>
<script>
$(document).ready(function(){
$("#toggleButton").click(function(){
$(".box").toggle(1000); // 1000毫秒切换效果
});
});
</script>
</body>
</html>
当提到jQuery特效代码时,通常是指使用jQuery库来创建一些动态、交互性强的效果。
淡入淡出效果:
html<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function(){
$("#fadeInButton").click(function(){
$("#fadeOutDiv").fadeIn();
});
$("#fadeOutButton").click(function(){
$("#fadeOutDiv").fadeOut();
});
});
</script>
<button id="fadeInButton">淡入</button>
<button id="fadeOutButton">淡出</button>
<div id="fadeOutDiv" style="width: 100px; height: 100px; background-color: lightblue; display: none;"></div>
滑动效果:
html<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function(){
$("#slideUpButton").click(function(){
$("#slideUpDiv").slideUp();
});
$("#slideDownButton").click(function(){
$("#slideUpDiv").slideDown();
});
});
</script>
<button id="slideUpButton">滑上</button>
<button id="slideDownButton">滑下</button>
<div id="slideUpDiv" style="width: 100px; height: 100px; background-color: lightgreen;"></div>
动画效果:
html<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function(){
$("#animateButton").click(function(){
$("#animateDiv").animate({width: '200px', height: '200px'}, 'slow');
});
});
</script>
<button id="animateButton">启动动画</button>
<div id="animateDiv" style="width: 100px; height: 100px; background-color: lightcoral;"></div>