博主信息
博文 87
粉丝 0
评论 0
访问量 72868
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
第十七节课作业:2. 3.在线相册管理器
黄忠倚的博客
原创
818人浏览过

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>在线相册管理器</title>
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<script type="text/javascript" src="./js/jquery-3.3.1.js"></script>
	<script type="text/javascript" src="./js/img.js"></script>

</head>
<body>
	<div class="wrap">
		<div class="header">
			<h2>在线相册管理器</h2>
			<p><label for="img_url">请输入图片地址</label>
			<!-- <input type="text" name="img_url" id="img_url" placeholder="./images/img.jpg"> -->
			<input type="text" name="img_url" id="img_url" placeholder="./images/img.jpg" value="./images/zly.jpg">
			</p>
			
			
			<p>请选择图片类型:
				<input type="radio" name="border" id="rect" value="0" checked="">
				<label for="">矩形</label>
				<input type="radio" name="border" id="radius" value="10%">
				<label for="">圆角</label>
				<input type="radio" name="border" id="circle" value="50%">
				<label for="">圆形</label>
			</p>
			
			<p>图片是否添加阴影:
			<select name="shadow" id="">
					<option value="0" selected="">不添加</option>
					<option value="1">添加</option>
			</select>
					<p><button class="add">添加图片</button></p>
				</p>
		</div>
		<div class="main">
			<ul></ul>
		</div>
	</div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

.wrap {
	width: 400px;
	height: auto;
	background-color: lightyellow;
	border: 1px solid #cecece;
	color: #363636;
}

.wrap .header {
	padding:15px;
}

.wrap .header h2 {
	text-align: center;
}

.add {
	width:100px;
	height: 30px;
	border:none;
	background-color: skyblue;
	color:white;
}

.add:hover {
	background-color: orange;
	font-size: 1.1em;
	cursor: pointer;
}

.main {
	overflow: hidden;
}

.main ul {
	margin:0;
	padding:0;
}

.main ul li {
	list-style: none;
	float: left;
	margin-left: 20px;
	margin-bottom: 10px;
	width: 170px;
	height: 200px;
	text-align: center;
}

.main ul li button {
	margin:3px;
	border:none;
	border-radius: 20%;
	background-color: lightgreen;

}

.main ul li button:hover {
	background-color:orange;
	color:white;
	cursor:pointer;

运行实例 »

点击 "运行实例" 按钮查看在线实例

实例

$(document).ready(function(){
	//给按钮添加点击事件
	$('button.add').on('click',function(){
		//第一步,获取图片的相关信息
		var img_url = $('#img_url').val()
		// console.log(img_url)
		// 1.如果用户没有输入图片地址,则提示用户:
		if (img_url.length == 0) {
			alert('请选择一张图片')
			$('img_url').focus()
			return false
		}

		//2.获取图片类型
		var img_type = $(':radio:checked').val()
		// console.log(img_type)
		
		//3.判断是否添加阴影
		var shadow = 'none'
		if ($(':selected').val() == 1) {
			shadow = '3px 3px 3px #666'
		}
		// console.log(shadow)
		
		// 第二步,创建图片元素,并把相关的属性添加上
		var img = $('<img>')
			.prop('src',img_url)
			.width(170)
			.height(170)
			.css({
				'border-radius':img_type,
				'box-shadow':shadow
			})

			//给相册添加移动和删除功能
			//创建三个按钮
			var before = $('<button>').text('前移')
			var after = $('<button>').text('后移')
			var remove = $('<button>').text('删除')

			//将这三个按钮添加到图片下面
			//$('<li>') 创建出一个<li>元素并把<img>和三个操作按钮添加到<li>内容的后面
			var li = $('<li>').append(img,before,after,remove)

			//第三步,将图片添加到页面中
			li.appendTo('ul')
			
			///////////////////////////////////////
			//前移操作:将前一个图片作为插入点,在此之前插入当前图片
			before.click(function(){
				// console.log($(this))
				$(this).parent().prev().before($(this).parent())
			})	

			//后移操作:将前一个图片作为插入点,在此之后插入当前图片
			after.click(function(){
				// console.log($(this))
				$(this).parent().next().after($(this).parent())
			})	

			//删除操作:
			remove.click(function(){
				// console.log($(this))
				$(this).parent().remove()
			})	
	})
})

运行实例 »

点击 "运行实例" 按钮查看在线实例


批改状态:未批改

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学