js--Mobile Avatar Click on the display button position Adaptive

Source: Internet
Author: User

In the mobile page, the Avatar Display Div, the last of the first line to click to show more Buttons (more), because the phone width of the size of the inconsistent, so the number of images per row is not consistent, the position of the more button is always fixed in the last row, so you need to calculate the size of the screen width, Then according to the size of each Li to calculate the maximum number of rows can be placed, and then the more through JS inserted, such as

IPhone5 displays as follows:

IPhone6 displays as follows:

A bit of sticker code:

Html

<div class= "pic" >        <ul>            <li></li>            <li>< IMG src= "img/d.png"/></li>            <li></li>            <li></li>            <li></li> <li></li>            <li></li> <li></li>            <li></li> <li></li>            <li></li> <li></li>            <li></li> <li            class=" Last "></ li>        </ul>    </div>

  

Css

       . pic{            height:100px;            Overflow:hidden;        }        . Pic ul{            padding:0 20px;        }        . Pic ul li{            width:60px;            height:60px;            margin:20px 10px 20px 15px;            Float:left;            border-radius:50%;            Text-align:center;            line-height:55px;        }        . Pic ul li img {            padding:0;        }        . Pic li.more{            margin-right:0px;            Background:url (img/more.png) no-repeat Center Center;        }        . Pic li.last{            Background:url (img/more.png) no-repeat Center Center;        }

JS Code

function LoadPage () {var clientw = $ (window). width (); /*===================*//*===================*//*===================*/$ (". Last"). Hide (); Set the last click to close the Avatar frame//settings. More position, depending on the width of the set up position/*===================*//*===================            */var lis =$ (". Pic"). Find ("Li"). length; If all of the li var index = parseint ((clientW-70)/80);//How many rows can be loaded on this basis-1 represents the left and last position in a row//alert ($ (". Pic ul")            );             if (Index < LIS) {$ (". Pic"). Find ("Li"). EQ (index-1). Before ("<li class= ' more ' ></li>");//Key, Essence            }}$ (". more"). Click (function () {//Click to display $ (". Last"). Show ();            $ (". Pic"). CSS ("Overflow", "visible");            $ (". Pic ul"). CSS ("padding-right", "0");        $ (this). Hide ();        });            $ (". Last"). Click (function () {//Click Hide $ (". Pic"). CSS ("Overflow", "hidden");            $ (". more"). Show (); $(". pic ul "). CSS (" Padding-right "," 20px ");        $ (this). Hide (); });

 

This function is as follows

Before clicking

After clicking

Click on it or hide it

js--Mobile Avatar Click on the display button position Adaptive

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.