簡體   English   中英

jQuery-使用以下方法在一列中列出Flickr照片 <ul><li></li></ul> 標簽

[英]jQuery - List Flickr photos in one column using <ul><li></li></ul> tags

我有以下代碼...

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Flickr</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"/>
    <script src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#photoform').submit(function () {
                var keyword = $('#keyword').val();

                $('#photolist').html('Please wait...');
                $.getJSON('http://api.flickr.com/services/feeds/photos_public.gne?tags=' + keyword + '&format=json&jsoncallback=?',
                    function (data) {
                        $('#photolist').empty();
                        $.each(data.items, function (index, item) {
                            $('#photolist').append('<li><img src="' + item.media.m + '" align="left"/></li><br />');
                        });
                    }
                );

                return false;
            });
        });
    </script>

    <style type="text/css">
        #photos {
            margin-top: 20px;
        }
        #photos img {
            height: 200px;
            width: 250px;
            margin-right: 10px;
            margin-bottom: 10px;
        }
    </style>
</head>
<body>
    <div data-role="page" id="photos">
        <form method="get" name="photoform" id="photoform">
            Keyword: <input type="text" name="keyword" id="keyword" value="" /><input type="submit" name="findphoto" id="findphoto" value="Find" />

            <ul data-role="listview" data-filter="false" id="photolist"></ul>
        </form>
    </div>
</body>
</html>

我想將Flickr API照片顯示為一列

<ul><li></li></ul>

標簽。 有關示例,請參考代碼中的$ .getJSON。 但是,當我運行它時,它不會將照片吐出一列。 它會將它們吐出5列。 有什么建議么?

我在這里查看您的代碼的一部分:

$('#photolist').append('<li><img src="' + item.media.m + '" align="left"/></li><br />');

這表明圖像將一個顯示在另一個之上。 如果是這種情況,但您對此不滿意,則應建議您將圖像排成一行。

如果是這樣,則應將上一行更改為下一行:

$('#photolist').append('<li><img src="' + item.media.m + '" align="left"/></li>');

還要在樣式表聲明中添加以下內容:

ul#photolist li{
width: 20%;
display: inline-block;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM