Blogger Information
Blog 34
fans 0
comment 1
visits 23362
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
jQuery中的基本操作(二) —2018年9月18日23时45分
感恩的心的博客
Original
702 people have browsed it

实战: 在线相册


实例

<!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>

运行实例 »

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

Correction status:Uncorrected

Teacher's comments:
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