博客列表 >jQuery中的基本操作(二) —2018年9月18日23时45分

jQuery中的基本操作(二) —2018年9月18日23时45分

感恩的心的博客
感恩的心的博客原创
2018年09月26日 20:43:26698浏览

实战: 在线相册


实例

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>jQuery Ablum</title>
        <Script src="../0917/lib/jquery.js"></Script>
            <style>
        .warp {
            width: 360px;
            height: auto;
            background-color: #efefef;
            border: 3px 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-color: skyblue;
            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: lightgreen;
        }
        .main ul li button:hover {
            background-color: orange;
            color: white;
            cursor: pointer;
        }

    </style>
    </head>
    <body>
        <div class="warp">
            <div class="header">
                <h2>Good Person</h2>
                <p>
                <lable for="img_url">Please Choose Picture</lable>
                <input type="file" name="img_url" id="img_url" placeholder="address">
                </p>
                <p>
                    Picture Style:
                    <input type="radio" id="rect" name="border" value="0"><label for="rect">Orthogonal Angel</label>
                    <input type="radio" id="radius" name="border" value="10%"><label for="radius">Fillet Angel</label>
                    <input type="radio" id="circle" name="border" value="50%"><label for="circle">Cycle</label>
                </p>
                <p>Shadow:
                    <select name="shadow">
                        <option value="0">Not Add</option>
                        <option value="1">Add</option>
                    </select>
                </p>
                <p><button class="add">Add picture</button></p>
            </div>
            <div class="main">
                <ul>
                    <!--<li>-->
                    <!--<img src="" alt="">-->
                    <!--<button>前</button>-->
                    <!--<button>后</button>-->
                    <!--<button>删</button>-->
                    <!--</li>-->
                </ul>
            </div>
        </div>

        <script>
            $(function(){

                $('button.add').on('click',function(){
                    let img_url=$('#img_url').val();
                    console.log('url1:'+img_url);
                    if(0===img_url.length){
                        alert('Please choose a picture.');
                        $('#img_url').focus();
                        return false;
                    }
                

                //get style of picture
                let img_type=$(':radio:checked').val();
                let shadow='none';
                if($(':selected').val()==='1'){
                    shadow='3px 3px 3px #666';
                }

                //Create picture and add to the page
                console.log('url2:'+img_url);
                img_url = 'http://www.php.io/0918/images/'+img_url.split('\\')[2];
                console.log(img_url);

                //Create a picture
                let img=$('<img/>')
                        .prop('src',img_url)
                        .width(150)
                        .height(150)
                        .css({
                            'border-radius':img_type,
                            'box-shadow':shadow
                        });

                let before=$('<button></button>').text('前移');
                let after=$('<button></button>').text('后移');
                let remove=$('<button></button>').text('删除');

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

                before.click(function(){
                    let current=$(this).parent();
                    let prev=current.prev();
                    prev.before(current);
                });

                after.click(function(){
                    let current=$(this).parent();
                    let next=current.next();
                    next.after(current);
                });


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




});


            });


        </script>


    </body>
</html>

运行实例 »

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

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议