Blogger Information
Blog 48
fans 0
comment 0
visits 36351
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
武林高手在线相册-2018.09.18
雨天的博客
Original
669 people have browsed it

实例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>在线相册管理</title>
    <script src="jquery-3.3.1.js"></script>
</head>
<style>
    .warp{
        width: 360px;
        height: auto;
        background: #efefef;
        border: 2px double grey;
        color: #363636;
        border-radius: 2%;
    }
    .warp .header{
        padding: 15px;
    }
    .warp .header h2{
        text-align: center;
    }
    .add{
        width: 100px;
        height: 30px;
        border: none;
        cursor: pointer;
        background: skyblue;
        color: #FFF;
    }
    .add:hover{
        background: orange;
        font-size: 1.1rem;
    }
    .main{
        overflow: hidden;
    }
    .main ul{
        padding: 0;
        margin: 0;
    }
    .main ul li{
        list-style: 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: #00F7DE;
    }
    .main ul li button:hover{
        background: #eb7350;
        color: white;
        cursor: pointer;
    }
</style>
<body>
    <div class="warp">
        <div class="header">
            <h2>在线相册管理</h2>
            <p>
                <label for="imgUrl">输入图片地址</label>
                <input type="file" name="imgUrl" id="imgUrl" placeholder="图片地址">
            </p>
            <p>
                图片类型
                <input type="radio" id="rect" name="border" value="0"><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>是否添加阴影:
                <select name="shadow" id="">
                    <option value="0">不添加</option>
                    <option value="1">添加</option>
                </select></p>
            <p><button class="add">添加图片</button></p>
        </div>
        <div class="main">
            <ul></ul>
        </div>
    </div>
    <script>
        //分为三步

        $(function () {
            //1.获取图片的相关信息
            $('button.add').on('click',function () {
                //判断用户是否选择了图片
                let imgUrl = $('#imgUrl').val();
              //console.log(imgUrl.split('\\')[2])
               imgUrl = 'http://localhost/0918/img/'+(imgUrl.split('\\')[2]);
                if(imgUrl.length == 0)
                {
                    alert('请选择一张图片');
                    $('#imgUrl').focus();
                    return false;
                }
                //获取图片的基本特征
                //获取到图片的外观
               let imgType = $(':radio:checked').val();

                //是否添加阴影
                let shadow = 'none';

                //console.log($(':selected').val())
                if($(':selected').val() == 1)
                {
                    shadow = '3px 3px 3px #666';
                }
                //2.创建图片并添加到页面中

                //创建一个图片
                let img = $('<img>')
                    .prop('src',imgUrl)
                    .width(150)
                    .height(150)
                    .css({
                    'border-radius':imgType,
                    'box-shadow':shadow,
                })
                //创建按钮
                let before = $('<button></button>').text('前移');
                let after = $('<button></button>').text('后移');
                let remove = $('<button></button>').text('删除');

                //创建一个Li用来放所有的内容
                let contier = $('<li></li>');
                contier.append(img,before,after,remove);
                //将li添加到页面的ul中
               $('ul').append(contier);
                //$('ul').append('<li>aaaa</li>')

                //3.为三个操作添加功能
                //前移功能
                before.on('click',function () {
                    //获取到要移动的图片
                    let current = $(this).parent();
                    let prev = current.prev();//获取前一个元素
                    //在前一个元素之前将当前元素插入,实际就是交换下位置
                    prev.before(current);

                })
                //后移功能
                after.on('click',function () {
                    //获取到要移动的图片
                    let current = $(this).parent();
                    let next = current.next();//获取后一个元素
                    //在后一个元素之后将当前元素插入,实际就是交换下位置
                    next.after(current);

                })
                //删除
                remove.on('click',function () {
                    if(confirm('确定删除吗?'))
                    {
                        $(this).parent().remove();
                    }
                    return false;
                })

            })


        });


    </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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!