Blogger Information
Blog 63
fans 1
comment 0
visits 75917
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
动态相册管理器
桃儿的博客
Original
818 people have browsed it

动态相册管理器

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态相册管理器</title>
    <style>
        .warp {
            width: 360px;
            height: auto;
            background-color: linen;
            border: 3px double grey;
            color: #363636;
            border-radius: 2%;
            box-shadow: 2px 2px 2px #888;
        }
        .warp .header {
            padding: 15px;
        }
        .warp .header h2 {
            text-align: center;
        }
        .add {
            width: 100px;
            height: 30px;
            border: none;
            cursor: pointer;
            background-color: deepskyblue;
            color: white;
        }
        .add:hover {
            background-color: orange;
            font-size: 1.1rem;
        }
        .main {
            overflow: hidden;
        }

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

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

        .main ul li button {
            margin: 3px;
            border: none;
            border-radius: 5%;
            background-color: deepskyblue;
        }
        .main ul li button:hover {
            background-color: orange;
            color: white;
            cursor: pointer;
        }

    </style>
</head>
<body>
<div class="warp">
    <div class="header">
        <h2>动态相册管理器</h2>
        <p>
            <label for="img_url">输入图片地址</label>
            <input type="file" name="img_url" id="img_url" placeholder="图片地址">
        </p>
        <p>
            图片类型:
            <input type="radio" id="rect" name="border" value="0" checked><label for="rect">直角</label>
            <input type="radio" id="radius" name="border" value="10%"><label for="radius">圆角</label>
            <input type="radio" id="circle" name="border" value="50%"><label for="circle">圆形</label>
        </p>
        <p>
            <label for="shadow">是否添加阴影:</label>
            <select name="shadow" id="shadow">
                <option value="0" selected>不添加</option>
                <option value="1">添加</option>
            </select>
        </p>
        <p><button class="add">添加图片</button></p>
    </div>
    <div class="main">
        <ul>
                        <!--<li>-->
                            <!--<img src="http://html.io/0521/static/images/2.jpg" alt="" width="150">-->
                            <!--<button>前移</button>-->
                            <!--<button>后移</button>-->
                            <!--<button>删除</button>-->
                        <!--</li>-->
        </ul>
    </div>
</div>

<script src="static/js/jquery-3.4.1.js"></script>
<script>
    $(function () {
        //分三步完成
        $('.add').on('click',function () {
            //1.获取图片信息
            //判断用户是否选择了图片?
            var img_url=$('#img_url').val();
            if(img_url.length===0){
                alert('请选择一张图片上传');
                $('#img_url').focus();
                return false;
            }
            //获取图片的外观特征
            var img_type = $('input[type="radio"]:checked').val();
            var shadow='none';
            if($(':selected').val()===1){
                shadow='2px 2px 2px #888';
            }
            //2.创建图片并添加到页面中
            // console.log(img_url);
            //split():将字符串按指定字符切割为数组
            // console.log(img_url.split('\\')[2]);
            var realImgUrl=img_url.split('\\')[2];
            img_url='http://html.io/0521/static/images/'+realImgUrl;
            // console.log(img_url);

            //创建图片与按钮,并打包到一个容器中,添加到页面中
            var img=$('<img>').attr({
                src:img_url,
                width:150,
                height:150,
                alt:'明星相册'
            }).css({
                'border-radius':img_type,
                'box-shadow':shadow
            });
            //三个操作按钮
            var before=$('<button>').text('前移');
            var after=$('<button>').text('后移');
            var remove=$('<button>').text('删除');

            var container=$('<li>');
            container.append(img,before,after,remove);
            container.appendTo('ul');

            //为三个按钮添加功能
            //前移
            before.on('click',function () {
                //先拿到要移动的图片
                var current=$(this).parent();
                var prev=current.prev();
                prev.before(current);
            });
            //后移
            after.on('click',function () {
                //先拿到要移动的图片
                var current=$(this).parent();
                var next=current.next();
                next.after(current);
            });
            //删除
            remove.on('click',function () {
                if(confirm("真的不要我了吗?")){
                    $(this).parent().remove();
                }
            })
        })
    })
</script>
</body>
</html>

运行实例 »

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



Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post