【fgm.cc练习2-11】鼠标移过,改变图片路径

本文介绍了如何使用HTML、CSS和JavaScript实现鼠标移过小图片时,大图片显示相应内容的交互效果。通过实例练习,强调了实践在学习过程中的重要性,提倡不断尝试和修改以掌握技术。
摘要由CSDN通过智能技术生成

练习地址:http://www.fgm.cc/learn/lesson2/11.html
在这里插入图片描述
实现效果:鼠标移到小图片上,大图片改变为相应的小图片。
实现思路:跟上篇套路一样,这里主要用到flex布局。
代码如下:

HTML
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>鼠标移过,改变图片路径</title>
	<link rel="stylesheet" type="text/css" href="11_changePath.css">
</head>
<body>
	<div id="container">
		<div id="show"></div>
		<div id="col"></div>
		<div id="row"></div>
	</div>
	<script type="text/javascript" src="11_changePath.js"></script>
</body>
</html>
CSS
html, body {
	background: black;
}
#container {
	width: 215px;
	height: 275px;
	margin: 0 auto;
	border-radius: 5%;
	background: white;
	padding: 10px;
	padding-bottom: 5px;
}
#show {
	width: 160px;
	height: 160px;
	background: url("../../photos/1.jpg");
	background-size: 100%;
}
#col {
	position: relative;
	top: -160px;
	right: -165px;
	display: flex;
	flex-direction: column;
}
#row {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	width: 170px;
	position: relative;
	top: -270px;
}
.col, .row {
	width: 50px;
	height: 50px;
	margin-bottom: 5px;
}
.col {
	/*border: 1px solid black;*/
}
.row {
	/*border: 1px solid black;*/
	margin-right: 5px;
}
JavaScript
window.onload = function() {
	var col = document.getElementById("col");
	var row = document.getElementById("row");
	var show = document.getElementById("show");
	for(var i=0; i<5; i++){
		var photo = document.createElement("div");
		col.appendChild(photo);
		photo.className = "col";
		photo.style.background = "url(../../photos/"+(i+1)+".jpg";
		photo.style.backgroundSize = "100%";
		photo.onmouseover = (function(n) {
			return function() {
				show.style.background = "url(../../photos/"+(n+1)+".jpg";
				show.style.backgroundSize = "100%";
			}
		})(i);
	}
	for(var i=0; i<6; i++){
		var photo = document.createElement("div");
		row.appendChild(photo);
		photo.className = "row";
		photo.style.background = "url(../../photos/"+(i+6)+".jpg";
		photo.style.backgroundSize = "100%";
		photo.onmouseover = (function(n) {
			return function() {
				show.style.background = "url(../../photos/"+(n+6)+".jpg";
				show.style.backgroundSize = "100%";
			}
		})(i);
	}
}

其实还有一个,实践出真知。只有不断的修改达到所要的样式,才知道某个东西具体是怎么用的(我也知道看书很枯燥呜呜…)
最后还有一个啦!我的千玺好看吗哈哈哈哈 哈哈哈哈…这系列练习要用多张图片的时候懒得找,就直接用电脑里的handsome千玺了嘻嘻。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PSO-FGM (Particle Swarm Optimization with Firefly Algorithm-based Gaussian Mutation) 是一种结合了粒子群优化(Particle Swarm Optimization, PSO)和萤火虫算法(Firefly Algorithm, FA)以及高斯变异操作的混合优化方法。这种算法通常用于解决复杂的优化问题,如函数拟合、参数估计或机器学习中的超参数调优。 由于这是一个比较技术性的主题,我会提供一个简单的概念概述,但完整的代码会包含以下几个部分: 1. 初始化粒子群体:粒子代表可能的解,每个粒子具有位置(表示当前解决方案)和速度(决定搜索方向)。 2. PSO 更新:根据个人最佳解(pBest)和全局最佳解(gBest),粒子的速度和位置会被更新。 3. FA 部分:模仿萤火虫间的光吸引行为,依据光源强度(目标函数值)调整飞行距离和亮度。 4. FGM 操作:基于高斯分布的变异策略,对粒子的位置进行随机微扰,增加搜索多样性。 5. 判断收敛条件:比如达到最大迭代次数,或者解的质量不再显著提高,则停止优化。 下面是简化的伪代码示例: ```python def PSO_FGM(optimizer_params, problem_func): # 初始化粒子和变量 particles = initialize_particles(optimizer_params) gBest = find_initial_gBest(particles) for t in range(optimizer_params['max_iterations']): # PSO 更新 update_velocities(particles, gBest) update_positions(particles) # FA 光吸引 attract_fires(particles, gBest) # FGM 高斯变异 apply_gaussian_mutation(particles) # 新的全局最优解 new_gBest = update_global_best(particles) if is_converged(new_gBest, gBest): break return gBest, particles # ...定义具体的方法(如初始化、更新等) ``` 实际代码会更复杂,因为涉及很多细节计算,包括概率计算、邻域搜索等。如果你想获得具体的代码实现,建议查阅相关的开源库或研究论文,或者在线搜索相应的教程。如果你有关于这个算法的具体问题,例如如何实现某个步骤,请告诉我,我会进一步解释。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值