jquery动态网站
时间: 2023-12-30 15:23:46 浏览: 100
构建动态网站
以下是两种使用jQuery实现动态网站的例子:
1. 使用jQuery动画插件创建动感效果
```html
<!DOCTYPE html>
<html>
<head>
<title>动态网站</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="动画插件.js"></script>
<link rel="stylesheet" href="动画插件样式.css">
</head>
<body>
<div class="box">这是一个动态的盒子</div>
<button id="animateBtn">点击开始动画</button>
<script>
$(document).ready(function(){
$("#animateBtn").click(function(){
$(".box").animate({left: '250px'}, "slow");
});
});
</script>
</body>
</html>
```
动画插件.js:
```javascript
$(document).ready(function(){
$(".box").click(function(){
$(this).animate({left: '250px'}, "slow");
});
});
```
动画插件样式.css:
```css
.box {
width: 100px;
height: 100px;
background-color: red;
position: relative;
}
button {
margin-top: 20px;
}
```
2. 使用jQuery实现按钮图标的动画
```html
<!DOCTYPE html>
<html>
<head>
<title>动态网站</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="按钮动画插件.js"></script>
<link rel="stylesheet" href="按钮动画插件样式.css">
</head>
<body>
<button class="loda-btn">点击加载</button>
<script>
$(document).ready(function(){
$(".loda-btn").click(function(){
$(this).addClass("load-icon");
setTimeout(function(){
$(".loda-btn").removeClass("load-icon");
}, 2000);
});
});
</script>
</body>
</html>
```
按钮动画插件.js:
```javascript
$(document).ready(function(){
$(".loda-btn").click(function(){
$(this).addClass("load-icon");
setTimeout(function(){
$(".loda-btn").removeClass("load-icon");
}, 2000);
});
});
```
按钮动画插件样式.css:
```css
.loda-btn {
padding: 10px 20px;
background-color: blue;
color: white;
border: none;
cursor: pointer;
}
.load-icon::after {
content: "";
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
background-color: white;
margin-left: 5px;
animation: spin 2s infinite linear;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
```
阅读全文