<style> *{margin:0; padding:0;} body{background:#FFF7F7;} .img{width:50px; height: 50px; position: absolute; background-image: url("逆水寒/1366X768女.jpg"); background-size: cover;} </style> </head> <body> <div class="img"></div> </body> <script> let img = document.querySelector(".img") let deg = 0 let imgx = 0 let imgy = 0 let imgl = 0 let imgt = 0 let y = 0 let index = 0 window.addEventListener("mousemove",function(xyz){ imgx = xyz.x - img.offsetLeft - img.clientWidth /2 imgy = xyz.y - img.offsetTop - img.clientHeight /2 deg = 360*Math.atan(imgy/imgx)/(2*Math.PI) index= 0 let x = event.clientX if(img.offsetLeft<x){ y=-180 }else{ y=0 } }) setInterval(()=>{ img.style.transform = "rotateZ("+deg+"deg) rotateY("+y+"deg)" index++ if(index<50){ imgl+=imgx/50 imgt+=imgy/50 } img.style.left = imgl+"px" img.style.top = imgt+"px" },10) </script>
时间: 2024-03-08 21:45:10 浏览: 23
这段代码看起来像是一个简单的网页特效,使用了CSS和JavaScript来实现图片跟随鼠标移动旋转的效果。具体来说,代码中定义了一个带有背景图片的div元素(class为“img”),然后在JavaScript中监听鼠标移动事件,计算鼠标相对于图片中心点的位置,以此来计算图片需要旋转的角度和方向,并且根据鼠标移动的距离来让图片跟随鼠标移动。最后使用定时器不断更新图片的位置和角度,实现动态效果。
相关问题
create a html page with disney style for news website home page
Sure, here's a basic example of a Disney-style news website homepage:
```html
<!DOCTYPE html>
<html>
<head>
<title>Disney News</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<style>
body {
background-color: #f7e5df;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
header {
background-color: #3f51b5;
color: #fff;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 10px;
}
h1 {
margin: 0;
}
nav {
flex: 1;
margin-left: 10px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
justify-content: space-between;
}
nav li {
margin: 0 10px;
}
nav a {
color: #fff;
text-decoration: none;
text-transform: uppercase;
transition: color 0.2s ease-in-out;
}
nav a:hover {
color: #ffd700;
}
main {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
padding: 20px;
}
article {
background-color: #fff;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.3);
flex-basis: calc(33.33% - 20px);
margin-bottom: 20px;
overflow: hidden;
position: relative;
transition: box-shadow 0.2s ease-in-out;
}
article:hover {
box-shadow: 0 0 20px rgba(0,0,0,0.6);
}
article img {
width: 100%;
height: 200px;
object-fit: cover;
}
article h2 {
background-color: #ffd700;
color: #000;
font-size: 1.1rem;
margin: 0;
padding: 10px;
position: absolute;
bottom: 0;
left: 0;
right: 0;
}
article p {
padding: 10px;
margin: 0;
}
footer {
background-color: #3f51b5;
color: #fff;
display: flex;
justify-content: center;
padding: 10px;
}
</style>
</head>
<body>
<header>
<h1>Disney News</h1>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Movies</a></li>
<li><a href="#">TV Shows</a></li>
<li><a href="#">Theme Parks</a></li>
<li><a href="#">Merchandise</a></li>
</ul>
</nav>
</header>
<main>
<article>
<img src="https://via.placeholder.com/400x200" alt="Article Image">
<h2>Disney's Newest Movie</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis leo sapien. In et rhoncus justo. Curabitur pretium urna vel nisl lobortis, eu ullamcorper metus fringilla.</p>
</article>
<article>
<img src="https://via.placeholder.com/400x200" alt="Article Image">
<h2>Behind the Scenes of Frozen 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis leo sapien. In et rhoncus justo. Curabitur pretium urna vel nisl lobortis, eu ullamcorper metus fringilla.</p>
</article>
<article>
<img src="https://via.placeholder.com/400x200" alt="Article Image">
<h2>New Disney+ Original Series</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis leo sapien. In et rhoncus justo. Curabitur pretium urna vel nisl lobortis, eu ullamcorper metus fringilla.</p>
</article>
<article>
<img src="https://via.placeholder.com/400x200" alt="Article Image">
<h2>Disney's Latest Theme Park Expansion</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis leo sapien. In et rhoncus justo. Curabitur pretium urna vel nisl lobortis, eu ullamcorper metus fringilla.</p>
</article>
<article>
<img src="https://via.placeholder.com/400x200" alt="Article Image">
<h2>New Disney Princess Merchandise</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis leo sapien. In et rhoncus justo. Curabitur pretium urna vel nisl lobortis, eu ullamcorper metus fringilla.</p>
</article>
<article>
<img src="https://via.placeholder.com/400x200" alt="Article Image">
<h2>Upcoming Live-Action Disney Remakes</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer quis leo sapien. In et rhoncus justo. Curabitur pretium urna vel nisl lobortis, eu ullamcorper metus fringilla.</p>
</article>
</main>
<footer>
<p>© Disney News 2021</p>
</footer>
</body>
</html>
```
This is just a starting point, and you can customize the design and content to fit your specific needs.
自己设计一个网页,基本要求如下: 1.网页中的各个元素的DOM结构设置合理,在网页中显示出的样式美观大方; 网页中的元素要有动态交互效果,即:使用iQuery编程来是实现网页中的交互 交互效果中要包含有5个以上不同事件的效果(包括动画效果);
好的,我将为您设计一个简单的网页,包含以下内容:
1. 一个导航栏,包含几个链接,点击链接可以跳转到对应的页面。
2. 一个幻灯片展示区域,可以自动播放图片。
3. 一个搜索框,可以输入关键字进行搜索。
4. 一个产品展示区域,包含多个产品卡片,可以通过鼠标悬停或点击实现不同的效果。
5. 一个联系我们区域,包含一个表单和一个提交按钮。
首先,我们需要编写 HTML 代码来构建网页的基本结构。代码如下:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>My Website</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<nav>
<ul>
<li><a href="#">首页</a></li>
<li><a href="#">产品</a></li>
<li><a href="#">关于我们</a></li>
<li><a href="#">联系我们</a></li>
</ul>
</nav>
</header>
<section class="slider">
<img src="slider1.jpg" alt="slider1">
<img src="slider2.jpg" alt="slider2">
<img src="slider3.jpg" alt="slider3">
</section>
<section class="search">
<input type="text" placeholder="请输入关键字">
<button>搜索</button>
</section>
<section class="products">
<div class="card">
<img src="product1.jpg" alt="product1">
<h3>产品名称</h3>
<p>产品描述</p>
<a href="#">查看详情</a>
</div>
<div class="card">
<img src="product2.jpg" alt="product2">
<h3>产品名称</h3>
<p>产品描述</p>
<a href="#">查看详情</a>
</div>
<div class="card">
<img src="product3.jpg" alt="product3">
<h3>产品名称</h3>
<p>产品描述</p>
<a href="#">查看详情</a>
</div>
</section>
<section class="contact">
<form>
<label for="name">姓名:</label>
<input type="text" id="name">
<label for="email">邮箱:</label>
<input type="email" id="email">
<label for="message">留言:</label>
<textarea id="message"></textarea>
<button type="submit">提交</button>
</form>
</section>
<script src="jquery.min.js"></script>
<script src="script.js"></script>
</body>
</html>
```
接下来,我们需要编写 CSS 代码来美化网页。代码如下:
```css
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
margin: 0;
}
header {
background-color: #fff;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
padding: 10px;
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 999;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}
nav li {
margin-right: 20px;
}
nav a {
color: #333;
text-decoration: none;
font-size: 18px;
padding: 5px 10px;
border-radius: 5px;
transition: background-color 0.3s ease;
}
nav a:hover {
background-color: #ddd;
}
.slider {
height: 400px;
position: relative;
overflow: hidden;
}
.slider img {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
max-width: 100%;
max-height: 100%;
opacity: 0;
transition: opacity 0.5s ease;
}
.slider img.active {
opacity: 1;
}
.search {
margin: 50px auto;
text-align: center;
}
.search input[type="text"] {
padding: 10px;
border-radius: 5px;
border: none;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
width: 300px;
}
.search button {
padding: 10px 20px;
background-color: #333;
color: #fff;
border-radius: 5px;
border: none;
cursor: pointer;
transition: background-color 0.3s ease;
}
.search button:hover {
background-color: #555;
}
.products {
display: flex;
flex-wrap: wrap;
justify-content: center;
margin: 50px auto;
}
.card {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
border-radius: 5px;
overflow: hidden;
margin: 20px;
width: 300px;
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.card img {
width: 100%;
height: auto;
}
.card h3 {
font-size: 24px;
margin: 10px;
}
.card p {
font-size: 16px;
margin: 10px;
}
.card a {
display: block;
background-color: #333;
color: #fff;
padding: 10px 20px;
border-radius: 5px;
text-align: center;
margin: 10px;
transition: background-color 0.3s ease;
}
.card a:hover {
background-color: #555;
}
.contact {
background-color: #fff;
padding: 50px 0;
text-align: center;
}
.contact label {
display: block;
font-size: 18px;
margin-bottom: 10px;
}
.contact input[type="text"],
.contact input[type="email"],
.contact textarea {
padding: 10px;
border-radius: 5px;
border: none;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
width: 300px;
margin-bottom: 20px;
}
.contact button[type="submit"] {
padding: 10px 20px;
background-color: #333;
color: #fff;
border-radius: 5px;
border: none;
cursor: pointer;
transition: background-color 0.3s ease;
}
.contact button[type="submit"]:hover {
background-color: #555;
}
```
最后,我们需要编写 JavaScript 代码来实现网页的交互效果。代码如下:
```javascript
$(document).ready(function() {
// 幻灯片展示区域
var slideIndex = 0;
showSlides();
function showSlides() {
var slides = $('.slider img');
for (var i = 0; i < slides.length; i++) {
slides[i].classList.remove('active');
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1;
}
slides[slideIndex-1].classList.add('active');
setTimeout(showSlides, 5000);
}
// 产品展示区域
$('.card').hover(function() {
$(this).css('box-shadow', '0 4px 8px rgba(0,0,0,0.2)');
}, function() {
$(this).css('box-shadow', '0 2px 4px rgba(0,0,0,0.1)');
});
$('.card').click(function() {
$(this).toggleClass('selected');
});
// 联系我们区域
$('form').submit(function(e) {
e.preventDefault();
alert('提交成功!');
});
});
```
在这个 JavaScript 代码中,我们实现了以下交互效果:
1. 幻灯片展示区域会自动播放图片。
2. 产品展示区域的卡片在鼠标悬停时会有阴影效果,在点击时会有选中效果。
3. 联系我们区域的表单可以进行提交,并弹出提交成功的提示框。
至此,我们的网页设计完成了。您可以将这些代码保存到相应的文件中,然后在浏览器中打开进行预览。