如何创建类似Pinterest的脚本-步骤1

How to create Pinterest-like script - step 1
How to create Pinterest-like script - step 1

How to create Pinterest-like script – step 1 Do you like Pinterest? I am sure that yes, and, it is likely that you would like to create a similar photo website. I made up my mind to write a series of tutorials about development of similar script. For a start – let’s decide what features will be included into the script. I think, that besides of good design and friendly interface, we have to add next things: ajaxy popup to display full-size photos, possibility to write comments, like functionality, upload form, a way to sort photos (depends on its size) automatically and maybe something else. In our first lesson I prepared html markup with styles of our script. Also, in order to sort photos (align them) – I am going to use ‘masonry’ jQuery plugin.

如何创建类似Pinterest的脚本-步骤1您喜欢Pinterest吗? 我可以肯定,而且,您可能想创建一个类似的图片网站。 我下定决心要编写一系列有关类似脚本开发的教程。 首先–让我们决定脚本中将包含哪些功能。 我认为,除了良好的设计和友好的界面之外,我们还必须添加其他内容:显示全尺寸照片的ajaxy弹出窗口,编写评论的可能性(例如功能),上传表单,对照片进行排序的方式(取决于其大小)自动,也许还有其他东西。 在我们的第一课中,我准备了具有脚本样式的html标记。 另外,为了对照片进行排序(对齐)–我将使用“砌体” jQuery插件。

Now you can check our demonstration and download the sources:

现在,您可以检查我们的演示并下载源代码:

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

步骤1. HTML (Step 1. HTML)

As always, our first step is html markup. In the beginning – we have to include all the necessary styles and scripts in the head section:

与往常一样,我们的第一步是html标记。 首先,我们必须在头部添加所有必要的样式和脚本:


<!DOCTYPE html>
<html lang="en" >
    <head>
        <meta charset="utf-8" />
        <meta name="author" content="Script Tutorials" />
        <title>How to create Pinterest-like script - step 1 | Script Tutorials</title>
        <!-- add styles -->
        <link href="css/main.css" rel="stylesheet" type="text/css" />
        <!-- add scripts -->
        <script src="js/jquery.min.js"></script>
        <script src="js/jquery.masonry.min.js"></script>
        <script src="js/script.js"></script>
    </head>

<!DOCTYPE html>
<html lang="en" >
    <head>
        <meta charset="utf-8" />
        <meta name="author" content="Script Tutorials" />
        <title>How to create Pinterest-like script - step 1 | Script Tutorials</title>
        <!-- add styles -->
        <link href="css/main.css" rel="stylesheet" type="text/css" />
        <!-- add scripts -->
        <script src="js/jquery.min.js"></script>
        <script src="js/jquery.masonry.min.js"></script>
        <script src="js/script.js"></script>
    </head>

Now we can mark the main page structure. Schematically it looks like this:

现在我们可以标记主页结构。 示意图如下所示:


<body>
    <!-- header panel -->
    <div class="header_panel">
        <!-- logo -->
        <a href="#" class="logo"></a>
        <!-- search form -->
        <form action="" method="get" class="search">
            .....
        </form>
        <!-- navigation menu -->
        <ul class="nav">
            .....
        </ul>
    </div>
    <!-- upload form -->
    <a href="#x" class="overlay" id="add_form"></a>
    <div class="popup">
        .....
    </div>
    <!-- main container with pin elements -->
    <div class="main_container">
        .....
    </div>
</body>

<body>
    <!-- header panel -->
    <div class="header_panel">
        <!-- logo -->
        <a href="#" class="logo"></a>
        <!-- search form -->
        <form action="" method="get" class="search">
            .....
        </form>
        <!-- navigation menu -->
        <ul class="nav">
            .....
        </ul>
    </div>
    <!-- upload form -->
    <a href="#x" class="overlay" id="add_form"></a>
    <div class="popup">
        .....
    </div>
    <!-- main container with pin elements -->
    <div class="main_container">
        .....
    </div>
</body>

There are three main elements: header, upload form and main container (for pin elements). The header consists of a logo, search form and navigation menu. Look at its html markup:

有三个主要元素:标头,上传表单和主要容器(用于pin元素)。 标头由徽标,搜索表单和导航菜单组成。 查看其html标记:


    <!-- header panel -->
    <div class="header_panel">
        <!-- logo -->
        <a href="#" class="logo"></a>
        <!-- search form -->
        <form action="" method="get" class="search">
            <input autocomplete="off" name="q" size="27" placeholder="Search" type="text" />
            <input name="search" type="submit" />
        </form>
        <!-- navigation menu -->
        <ul class="nav">
            <li><a href="#add_form" id="login_pop">Add +</a></li>
            <li>
                <a href="#">About<span></span></a>
                <ul>
                    <li><a href="#">Help</a></li>
                    <li><a href="#">Pin It Button</a></li>
                    <li><a href="#" target="_blank">For Businesses</a></li>
                    <li class="div"><a href="#">Careers</a></li>
                    <li><a href="#">Team</a></li>
                    <li><a href="#">Blog</a></li>
                    <li class="div"><a href="#">Terms of Service</a></li>
                    <li><a href="#">Privacy Policy</a></li>
                    <li><a href="#">Copyright</a></li>
                    <li><a href="#">Trademark</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Profile<span></span></a>
                <ul>
                    <li><a href="#">Invite Friends</a></li>
                    <li><a href="#">Find Friends</a></li>
                    <li class="div"><a href="#">Boards</a></li>
                    <li><a href="#">Pins</a></li>
                    <li><a href="#">Likes</a></li>
                    <li class="div"><a href="#">Settings</a></li>
                    <li><a href="#">Logout</a></li>
                </ul>
            </li>
            <li>
                <a href="https://www.script-tutorials.com/pinterest-like-script-step-1/">Back to tutorial<span></span></a>
            </li>
        </ul>
    </div>

    <!-- header panel -->
    <div class="header_panel">
        <!-- logo -->
        <a href="#" class="logo"></a>
        <!-- search form -->
        <form action="" method="get" class="search">
            <input autocomplete="off" name="q" size="27" placeholder="Search" type="text" />
            <input name="search" type="submit" />
        </form>
        <!-- navigation menu -->
        <ul class="nav">
            <li><a href="#add_form" id="login_pop">Add +</a></li>
            <li>
                <a href="#">About<span></span></a>
                <ul>
                    <li><a href="#">Help</a></li>
                    <li><a href="#">Pin It Button</a></li>
                    <li><a href="#" target="_blank">For Businesses</a></li>
                    <li class="div"><a href="#">Careers</a></li>
                    <li><a href="#">Team</a></li>
                    <li><a href="#">Blog</a></li>
                    <li class="div"><a href="#">Terms of Service</a></li>
                    <li><a href="#">Privacy Policy</a></li>
                    <li><a href="#">Copyright</a></li>
                    <li><a href="#">Trademark</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Profile<span></span></a>
                <ul>
                    <li><a href="#">Invite Friends</a></li>
                    <li><a href="#">Find Friends</a></li>
                    <li class="div"><a href="#">Boards</a></li>
                    <li><a href="#">Pins</a></li>
                    <li><a href="#">Likes</a></li>
                    <li class="div"><a href="#">Settings</a></li>
                    <li><a href="#">Logout</a></li>
                </ul>
            </li>
            <li>
                <a href="https://www.script-tutorials.com/pinterest-like-script-step-1/">Back to tutorial<span></span></a>
            </li>
        </ul>
    </div>

As you see – everything is easy here. The second main element is upload form, I’m going to use the power of CSS3 to make CSS-based popup:

如您所见–这里一切都很容易。 第二个主要元素是上传表单,我将使用CSS3的功能来使基于CSS的弹出窗口:


    <!-- upload form -->
    <a href="#x" class="overlay" id="add_form"></a>
    <div class="popup">
        <div class="header">
            <a class="close" href="#close">x</a>
            <h2>Upload a Pin</h2>
        </div>
        <form>
            <input type="file" name="image_file" id="image_file" onchange="" />
        </form>
    </div>

    <!-- upload form -->
    <a href="#x" class="overlay" id="add_form"></a>
    <div class="popup">
        <div class="header">
            <a class="close" href="#close">x</a>
            <h2>Upload a Pin</h2>
        </div>
        <form>
            <input type="file" name="image_file" id="image_file" onchange="" />
        </form>
    </div>

You can find related CSS styles in the second step of our tutorial. Finally, it is important to review html markup of our photo units (or – pins):

您可以在本教程的第二步中找到相关CSS样式。 最后,重要的是查看我们的照片单元(或–引脚)的html标记:


    <div class="pin">
        <div class="holder">
            <div class="actions" pin_id="1">
                <a href="#" class="button">Repin</a>
                <a href="#" class="button">Like</a>
                <a href="#" class="button disabled comment_tr">Comment</a>
            </div>
            <a class="image ajax" href="#" title="Photo number 1" pin_id="1">
                <img alt="Photo number 1" src="photos/pic1.jpg">
            </a>
        </div>
        <p class="desc">Photo number 1 description</p>
        <p class="info">
            <span>1 likes</span>
            <span>1 repins</span>
        </p>
        <form class="comment" method="post" action="">
            <input type="hidden" name="id" value="1" />
            <textarea placeholder="Add a comment..." maxlength="1000"></textarea>
            <button type="button" class="button">Comment</button>
        </form>
    </div>

    <div class="pin">
        <div class="holder">
            <div class="actions" pin_id="1">
                <a href="#" class="button">Repin</a>
                <a href="#" class="button">Like</a>
                <a href="#" class="button disabled comment_tr">Comment</a>
            </div>
            <a class="image ajax" href="#" title="Photo number 1" pin_id="1">
                <img alt="Photo number 1" src="photos/pic1.jpg">
            </a>
        </div>
        <p class="desc">Photo number 1 description</p>
        <p class="info">
            <span>1 likes</span>
            <span>1 repins</span>
        </p>
        <form class="comment" method="post" action="">
            <input type="hidden" name="id" value="1" />
            <textarea placeholder="Add a comment..." maxlength="1000"></textarea>
            <button type="button" class="button">Comment</button>
        </form>
    </div>

Every pin consists of a holder element (action buttons and thumbnail image), description, info row, and comments box.

每个图钉均包含一个holder元素(动作按钮和缩略图),描述,信息行和注释框。

步骤2. CSS (Step 2. CSS)

Now, I would like to give you CSS styles to stylize today’s result. First section is base styles:

现在,我想给您CSS样式来风格化今天的结果。 第一部分是基本样式:

css / main.css (css/main.css)

/* base styles */
* {
    margin: 0;
    padding: 0;
}
html {
    background-color: #F7F5F5;
    font-size: 10px;
    font-family: arial,sans-serif;
}
a {
    color: #221919;
    text-decoration: none;
}

/* base styles */
* {
    margin: 0;
    padding: 0;
}
html {
    background-color: #F7F5F5;
    font-size: 10px;
    font-family: arial,sans-serif;
}
a {
    color: #221919;
    text-decoration: none;
}

Then, we can stylize our header area:

然后,我们可以样式化标题区域:


/* header elements */
.header_panel {
    background-color: #FAF7F7;
    box-shadow: 0 1px #FFFFFF inset, 0 1px 3px rgba(34, 25, 25, 0.4);
    height: 44px;
    left: 0;
    padding: 0 7px;
    position: relative;
    right: 0;
    top: 0;
    z-index: 1;
}
.logo {
    background: url("../images/logo.png") repeat scroll 0 0 transparent;
    display: block;
    height: 30px;
    left: 50%;
    margin-left: -50px;
    position: absolute;
    top: 10px;
    width: 100px;
}
.search {
    float: left;
    margin: 8px 0 0;
}
.search input[type=text] {
    background-color: #FAF7F7;
    border-color: #C2C0C0 #CCCACA #D1CFCF;
    border-image: none;
    border-style: solid;
    border-width: 1px;
    box-shadow: 0 1px #FFFFFF, 0 1px rgba(34, 25, 25, 0.05) inset;
    color: #8C7E7E;
    float: left;
    font-size: 13px;
    height: 16px;
    padding: 5px;
    width: 180px;
    -webkit-transition: all .5s;
    -moz-transition: all .5s;
    -ms-transition: all .5s;
    -o-transition: all .5s;
    transition: all .5s;
}
.search input[type=text]:focus {
    background-color: #FFFFFF;
    box-shadow: 0 1px #FFFFFF, 0 1px rgba(34, 25, 25, 0.1) inset;
    width: 250px;
}
.search input[type=submit] {
    background: url("../images/search.gif") no-repeat scroll center center transparent;
    border-color: #C2C0C0 #CCCACA #D1CFCF;
    border-style: solid;
    border-width: 1px;
    box-shadow: 0 1px rgba(255, 255, 255, 0.9), 0 0 2px rgba(255, 255, 255, 0.75) inset;
    color: transparent;
    content: "";
    cursor: pointer;
    float: left;
    height: 28px;
    margin-left: -1px;
    min-height: 17px;
    padding: 7px 7px 1px;
    width: 30px;
}
/* navigation styles */
.nav {
    float: right;
    position: relative;
}
.nav li {
    display: inline;
    font-size: 13px;
    position: relative;
}
.nav > li > a {
    color: #524D4D;
    cursor: pointer;
    display: inline-block;
    font-weight: bold;
    height: 29px;
    padding: 15px 27px 0 14px;
    position: relative;
    text-decoration: none;
    text-shadow: 0 1px #FFFFFF;
}
.nav > li > a span {
    background: url("../images/down.png") no-repeat scroll center top transparent;
    height: 6px;
    position: absolute;
    right: 14px;
    top: 20px;
    width: 7px;
}
.nav > li:hover > a {
    background-color: #E1DFDF;
    color: #221919;
    text-decoration: none;
    text-shadow: 0 1px rgba(255, 255, 255, 0.3);
}
.nav > li:active > a {
    background-color: #CB2027;
    color: #FFFFFF;
    text-shadow: 0 -1px rgba(34, 25, 25, 0.3);
}
.nav li ul {
    background-color: #FFFFFF;
    border-top: 1px solid #CCCACA;
    box-shadow: 0 2px 4px rgba(34, 25, 25, 0.5);
    display: none;
    left: 0;
    position: absolute;
    top: 28px;
    width: 140px;
    z-index: 1;
}
.nav li:hover ul {
    display: block;
}
.nav li ul a {
    color: #524D4D;
    display: block;
    font-weight: normal;
    padding: 7px 10px;
    text-align: left;
}
.nav li ul a:hover {
    background-color: #E1DFDF;
    color: #221919;
    text-decoration: none;
}
.nav li ul a:active {
    background-color: #CB2027;
    color: #FFFFFF;
}
.nav .div a {
    border-top: 1px solid #E1DFDF;
}
.nav > li:last-child ul {
    left: auto;
    right: 0;
}

/* header elements */
.header_panel {
    background-color: #FAF7F7;
    box-shadow: 0 1px #FFFFFF inset, 0 1px 3px rgba(34, 25, 25, 0.4);
    height: 44px;
    left: 0;
    padding: 0 7px;
    position: relative;
    right: 0;
    top: 0;
    z-index: 1;
}
.logo {
    background: url("../images/logo.png") repeat scroll 0 0 transparent;
    display: block;
    height: 30px;
    left: 50%;
    margin-left: -50px;
    position: absolute;
    top: 10px;
    width: 100px;
}
.search {
    float: left;
    margin: 8px 0 0;
}
.search input[type=text] {
    background-color: #FAF7F7;
    border-color: #C2C0C0 #CCCACA #D1CFCF;
    border-image: none;
    border-style: solid;
    border-width: 1px;
    box-shadow: 0 1px #FFFFFF, 0 1px rgba(34, 25, 25, 0.05) inset;
    color: #8C7E7E;
    float: left;
    font-size: 13px;
    height: 16px;
    padding: 5px;
    width: 180px;
    -webkit-transition: all .5s;
    -moz-transition: all .5s;
    -ms-transition: all .5s;
    -o-transition: all .5s;
    transition: all .5s;
}
.search input[type=text]:focus {
    background-color: #FFFFFF;
    box-shadow: 0 1px #FFFFFF, 0 1px rgba(34, 25, 25, 0.1) inset;
    width: 250px;
}
.search input[type=submit] {
    background: url("../images/search.gif") no-repeat scroll center center transparent;
    border-color: #C2C0C0 #CCCACA #D1CFCF;
    border-style: solid;
    border-width: 1px;
    box-shadow: 0 1px rgba(255, 255, 255, 0.9), 0 0 2px rgba(255, 255, 255, 0.75) inset;
    color: transparent;
    content: "";
    cursor: pointer;
    float: left;
    height: 28px;
    margin-left: -1px;
    min-height: 17px;
    padding: 7px 7px 1px;
    width: 30px;
}
/* navigation styles */
.nav {
    float: right;
    position: relative;
}
.nav li {
    display: inline;
    font-size: 13px;
    position: relative;
}
.nav > li > a {
    color: #524D4D;
    cursor: pointer;
    display: inline-block;
    font-weight: bold;
    height: 29px;
    padding: 15px 27px 0 14px;
    position: relative;
    text-decoration: none;
    text-shadow: 0 1px #FFFFFF;
}
.nav > li > a span {
    background: url("../images/down.png") no-repeat scroll center top transparent;
    height: 6px;
    position: absolute;
    right: 14px;
    top: 20px;
    width: 7px;
}
.nav > li:hover > a {
    background-color: #E1DFDF;
    color: #221919;
    text-decoration: none;
    text-shadow: 0 1px rgba(255, 255, 255, 0.3);
}
.nav > li:active > a {
    background-color: #CB2027;
    color: #FFFFFF;
    text-shadow: 0 -1px rgba(34, 25, 25, 0.3);
}
.nav li ul {
    background-color: #FFFFFF;
    border-top: 1px solid #CCCACA;
    box-shadow: 0 2px 4px rgba(34, 25, 25, 0.5);
    display: none;
    left: 0;
    position: absolute;
    top: 28px;
    width: 140px;
    z-index: 1;
}
.nav li:hover ul {
    display: block;
}
.nav li ul a {
    color: #524D4D;
    display: block;
    font-weight: normal;
    padding: 7px 10px;
    text-align: left;
}
.nav li ul a:hover {
    background-color: #E1DFDF;
    color: #221919;
    text-decoration: none;
}
.nav li ul a:active {
    background-color: #CB2027;
    color: #FFFFFF;
}
.nav .div a {
    border-top: 1px solid #E1DFDF;
}
.nav > li:last-child ul {
    left: auto;
    right: 0;
}

As you see – this is usual UL-LI based dropdown menu here. Well, now, the most interesting styles for today (CSS3-based upload form):

如您所见–这是此处通常基于UL-LI的下拉菜单。 好吧,现在,今天最有趣的样式(基于CSS3的上传表单):


/* popup upload form styles */
.overlay {
    background-color: #FFFFFF;
    bottom: 0;
    display: none;
    left: 0;
    opacity: 0.8;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 9;
}
.overlay:target {
    display: block;
}
.popup {
    background: none repeat scroll 0 0 #FCF9F9;
    border: 1px solid #F7F5F5;
    box-shadow: 0 2px 5px rgba(34, 25, 25, 0.5);
    display: inline-block;
    left: 50%;
    padding: 30px 30px 20px;
    position: fixed;
    top: 40%;
    visibility: hidden;
    width: 550px;
    z-index: 10;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    -webkit-transition: all 0.3s ease-in-out 0s;
    -moz-transition: all 0.3s ease-in-out 0s;
    -ms-transition: all 0.3s ease-in-out 0s;
    -o-transition: all 0.3s ease-in-out 0s;
    transition: all 0.3s ease-in-out 0s;
}
.overlay:target+.popup {
    top: 50%;
    opacity: 1 ;
    visibility: visible;
}
.popup .header {
    background-color: #F2F0F0;
    border-bottom: 1px solid #CCCACA;
    margin: -30px -31px 20px;
    padding: 18px 31px 8px;
    position: relative;
}
.popup .header h2 {
    color: #8C7E7E;
    font-size: 21px;
    line-height: 1em;
    margin: 0 37px 0 0;
    text-shadow: 0 1px #FFFFFF;
}
.popup .close {
    background: -webkit-linear-gradient(#FFFCFC, #F0EDED) repeat scroll 0 0 transparent;
    background: -moz-linear-gradient(#FFFCFC, #F0EDED) repeat scroll 0 0 transparent;
    background: linear-gradient(#FFFCFC, #F0EDED) repeat scroll 0 0 transparent;
    border-left: 1px solid rgba(34, 25, 25, 0.15);
    bottom: 0;
    box-shadow: 0 1px 2px #FFFFFF inset;
    color: #BBBBBB;
    display: block;
    font-size: 50px;
    line-height: 42px;
    position: absolute;
    right: 0;
    text-align: center;
    text-decoration: none;
    top: 0;
    width: 57px;
    z-index: 1;
}
.popup form input[type="file"] {
    font-size: 18px;
}

/* popup upload form styles */
.overlay {
    background-color: #FFFFFF;
    bottom: 0;
    display: none;
    left: 0;
    opacity: 0.8;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 9;
}
.overlay:target {
    display: block;
}
.popup {
    background: none repeat scroll 0 0 #FCF9F9;
    border: 1px solid #F7F5F5;
    box-shadow: 0 2px 5px rgba(34, 25, 25, 0.5);
    display: inline-block;
    left: 50%;
    padding: 30px 30px 20px;
    position: fixed;
    top: 40%;
    visibility: hidden;
    width: 550px;
    z-index: 10;
    -webkit-transform: translate(-50%, -50%);
    -moz-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    -o-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    -webkit-transition: all 0.3s ease-in-out 0s;
    -moz-transition: all 0.3s ease-in-out 0s;
    -ms-transition: all 0.3s ease-in-out 0s;
    -o-transition: all 0.3s ease-in-out 0s;
    transition: all 0.3s ease-in-out 0s;
}
.overlay:target+.popup {
    top: 50%;
    opacity: 1 ;
    visibility: visible;
}
.popup .header {
    background-color: #F2F0F0;
    border-bottom: 1px solid #CCCACA;
    margin: -30px -31px 20px;
    padding: 18px 31px 8px;
    position: relative;
}
.popup .header h2 {
    color: #8C7E7E;
    font-size: 21px;
    line-height: 1em;
    margin: 0 37px 0 0;
    text-shadow: 0 1px #FFFFFF;
}
.popup .close {
    background: -webkit-linear-gradient(#FFFCFC, #F0EDED) repeat scroll 0 0 transparent;
    background: -moz-linear-gradient(#FFFCFC, #F0EDED) repeat scroll 0 0 transparent;
    background: linear-gradient(#FFFCFC, #F0EDED) repeat scroll 0 0 transparent;
    border-left: 1px solid rgba(34, 25, 25, 0.15);
    bottom: 0;
    box-shadow: 0 1px 2px #FFFFFF inset;
    color: #BBBBBB;
    display: block;
    font-size: 50px;
    line-height: 42px;
    position: absolute;
    right: 0;
    text-align: center;
    text-decoration: none;
    top: 0;
    width: 57px;
    z-index: 1;
}
.popup form input[type="file"] {
    font-size: 18px;
}

This is a similar method as we used in our previous lesson (CSS3 Modal Popups). Well, now I have to give you final styles for the main container (for pin elements) and for single pin:

这与上一课( CSS3 Modal Popups )中使用的方法类似。 好了,现在我必须为您提供主容器(用于图钉元素)和单个图钉的最终样式:


/* photo pins - general styles */
.main_container {
    margin: 0 auto;
    padding: 10px 10px 0;
    position: relative;
}
.button {
    background-color: #F0EDED;
    background-image: -webkit-linear-gradient(center top , #FDFAFB, #F9F7F7 50%, #F6F3F4 50%, #F0EDED);
    background-image: -moz-linear-gradient(center top , #FDFAFB, #F9F7F7 50%, #F6F3F4 50%, #F0EDED);
    background-image: linear-gradient(center top , #FDFAFB, #F9F7F7 50%, #F6F3F4 50%, #F0EDED);
    border: 1px solid #BBBBBB;
    border-radius: 6px 6px 6px 6px;
    color: #524D4D;
    cursor: pointer;
    display: inline-block;
    float: right;
    font-weight: bold;
    line-height: 1em;
    margin: 0;
    padding: 5px 9px;
    text-align: center;
    text-shadow: 0 1px rgba(255, 255, 255, 0.9);
    -webkit-transition: all 0.2s ease-in-out 0s;
    -moz-transition: all 0.2s ease-in-out 0s;
    -ms-transition: all 0.2s ease-in-out 0s;
    -o-transition: all 0.2s ease-in-out 0s;
    transition: all 0.2s ease-in-out 0s;
}
.button:hover {
    box-shadow: 0 1px rgba(255, 255, 255, 0.35) inset, 0 0 0 1px rgba(140, 126, 126, 0.5), 0 1px 2px rgba(35, 24, 24, 0.75);
}
.button.disabled, .button[disabled] {
    background: none repeat scroll 0 0 #F2F0F0;
    border-color: #D1CDCD;
    color: #D1CDCD;
    cursor: default;
    text-shadow: 0 -1px rgba(34, 25, 25, 0.01);
}
/* single pin styles */
.pin {
    background-color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
    float: left;
    font-size: 11px;
    margin: 0 15px 15px 0;
    padding: 15px 15px 0;
    position: relative;
    width: 192px;
}
.pin .holder {
    position: relative;
}
.pin .actions {
    left: -8px;
    position: absolute;
    top: -8px;
    z-index: 3;
}
.pin .actions a {
    clear: none;
    display: none;
    float: left;
    margin: 0 5px 0 0;
}
.pin:hover .actions a {
    display: block;
}
.pin .image {
    background-color: #F2F0F0;
    cursor: -webkit-zoom-in;
    cursor: -moz-zoom-in;
    text-decoration: none;
}
.pin .image img {
    max-width: 192px;
    min-height: 75px;
    opacity: 1;
}
.pin .desc {
    margin: 10px 0 5px;
    overflow: hidden;
    word-wrap: break-word;
}
.pin .info {
    color: #8C7E7E;
    line-height: 1.35em;
    margin: 0 0 0.8em;
    overflow: hidden;
}
.pin .info span {
    float: left;
    margin-right: 10px;
}
.comment {
    background-color: #F2F0F0;
    border-top: 1px solid #D9D4D4;
    box-shadow: 0 1px #FCFAFA inset;
    margin: 0 -15px;
    overflow: hidden;
    padding: 10px 15px;
}
.comment textarea {
    background-color: #FCF9F9;
    border: 1px solid #CCCCCC;
    color: #8C7E7E;
    font-size: 11px;
    height: 21px;
    line-height: 1em;
    margin-bottom: 6px;
    padding: 4px 3px 3px;
    resize: none;
    width: 185px;
}
.comment textarea:focus {
    background-color: #FFFFFF;
    box-shadow: 0 1px 1px rgba(34, 29, 29, 0.1) inset;
}

/* photo pins - general styles */
.main_container {
    margin: 0 auto;
    padding: 10px 10px 0;
    position: relative;
}
.button {
    background-color: #F0EDED;
    background-image: -webkit-linear-gradient(center top , #FDFAFB, #F9F7F7 50%, #F6F3F4 50%, #F0EDED);
    background-image: -moz-linear-gradient(center top , #FDFAFB, #F9F7F7 50%, #F6F3F4 50%, #F0EDED);
    background-image: linear-gradient(center top , #FDFAFB, #F9F7F7 50%, #F6F3F4 50%, #F0EDED);
    border: 1px solid #BBBBBB;
    border-radius: 6px 6px 6px 6px;
    color: #524D4D;
    cursor: pointer;
    display: inline-block;
    float: right;
    font-weight: bold;
    line-height: 1em;
    margin: 0;
    padding: 5px 9px;
    text-align: center;
    text-shadow: 0 1px rgba(255, 255, 255, 0.9);
    -webkit-transition: all 0.2s ease-in-out 0s;
    -moz-transition: all 0.2s ease-in-out 0s;
    -ms-transition: all 0.2s ease-in-out 0s;
    -o-transition: all 0.2s ease-in-out 0s;
    transition: all 0.2s ease-in-out 0s;
}
.button:hover {
    box-shadow: 0 1px rgba(255, 255, 255, 0.35) inset, 0 0 0 1px rgba(140, 126, 126, 0.5), 0 1px 2px rgba(35, 24, 24, 0.75);
}
.button.disabled, .button[disabled] {
    background: none repeat scroll 0 0 #F2F0F0;
    border-color: #D1CDCD;
    color: #D1CDCD;
    cursor: default;
    text-shadow: 0 -1px rgba(34, 25, 25, 0.01);
}
/* single pin styles */
.pin {
    background-color: #FFFFFF;
    box-shadow: 0 1px 3px rgba(34, 25, 25, 0.4);
    float: left;
    font-size: 11px;
    margin: 0 15px 15px 0;
    padding: 15px 15px 0;
    position: relative;
    width: 192px;
}
.pin .holder {
    position: relative;
}
.pin .actions {
    left: -8px;
    position: absolute;
    top: -8px;
    z-index: 3;
}
.pin .actions a {
    clear: none;
    display: none;
    float: left;
    margin: 0 5px 0 0;
}
.pin:hover .actions a {
    display: block;
}
.pin .image {
    background-color: #F2F0F0;
    cursor: -webkit-zoom-in;
    cursor: -moz-zoom-in;
    text-decoration: none;
}
.pin .image img {
    max-width: 192px;
    min-height: 75px;
    opacity: 1;
}
.pin .desc {
    margin: 10px 0 5px;
    overflow: hidden;
    word-wrap: break-word;
}
.pin .info {
    color: #8C7E7E;
    line-height: 1.35em;
    margin: 0 0 0.8em;
    overflow: hidden;
}
.pin .info span {
    float: left;
    margin-right: 10px;
}
.comment {
    background-color: #F2F0F0;
    border-top: 1px solid #D9D4D4;
    box-shadow: 0 1px #FCFAFA inset;
    margin: 0 -15px;
    overflow: hidden;
    padding: 10px 15px;
}
.comment textarea {
    background-color: #FCF9F9;
    border: 1px solid #CCCCCC;
    color: #8C7E7E;
    font-size: 11px;
    height: 21px;
    line-height: 1em;
    margin-bottom: 6px;
    padding: 4px 3px 3px;
    resize: none;
    width: 185px;
}
.comment textarea:focus {
    background-color: #FFFFFF;
    box-shadow: 0 1px 1px rgba(34, 29, 29, 0.1) inset;
}

步骤3. JS (Step 3. JS)

We have just got over our big step with styles, and now I would like to give you a small piece of javascript:

我们刚刚结束了样式方面的重要一步,现在我想给您介绍一小段javascript:

js / script.js (js/script.js)

$(document).ready(function(){
    // masonry initialization
    $('.main_container').masonry({
        // options
        itemSelector : '.pin',
        isAnimated: true,
        isFitWidth: true
    });
    // onclick event handler (for comments)
    $('.comment_tr').click(function () {
        $(this).toggleClass('disabled');
        $(this).parent().parent().parent().find('form').slideToggle(250, function () {
            $('.main_container').masonry();
        });
    });
});

$(document).ready(function(){
    // masonry initialization
    $('.main_container').masonry({
        // options
        itemSelector : '.pin',
        isAnimated: true,
        isFitWidth: true
    });
    // onclick event handler (for comments)
    $('.comment_tr').click(function () {
        $(this).toggleClass('disabled');
        $(this).parent().parent().parent().find('form').slideToggle(250, function () {
            $('.main_container').masonry();
        });
    });
});

As you see – it is very easy to use masonry jQuery plugin, in the same time it does a great job – it aligns elements (pins) over the page.

如您所见-使用砌石jQuery插件非常容易,同时又做得很好-在页面上对齐元素(图钉)。

现场演示

结论 (Conclusion)

We have just finished our first lesson where we started making Pinterest-like script. I hope that you like it. It would be kind of you to share our materials with your friends. Good luck and welcome back!

我们刚刚完成了第一课,我们开始制作类似Pinterest的脚本。 我希望你喜欢。 您希望与朋友分享我们的资料。 祝你好运,欢迎回来!

翻译自: https://www.script-tutorials.com/pinterest-like-script-step-1/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值