Tips on jQuery's appand () and prepend () methods, jqueryappand

Source: Internet
Author: User

Tips on jQuery's appand () and prepend () methods, jqueryappand

Recently, a requirement is that a list is automatically rolled up. The table has many rows, but only one row is displayed and one row is rolled each time. The Code is as follows:

<div class="scroll-area">            <ul class="list1">                <li>                    <span class="phoneNum">111111111</span>                    <span class="award">101</span>                </li>                <li>                    <span class="phoneNum">222222222</span>                    <span class="award">102</span>                </li>                <li>                    <span class="phoneNum">333333333</span>                    <span class="award">103</span>                </li>                <li>                    <span class="phoneNum">444444444</span>                    <span class="award">104</span>                </li>            </ul>        </div>
.scroll-area {    height:40px;    overflow:hidden;    background-color:#fff4d7;    width:88%;    margin:0 auto;    border-radius:99px;}.scroll-area>ul {    margin:0;    padding:0;    font-size:15px;    color:#9b520b;    position:relative;    top:-40px;}.scroll-area>ul>li {    padding:9px 18px;}.scroll-area>ul>li>span {    vertical-align:sub;}.scroll-area>ul>li .award {    float:right;}
function Scroll(height,num){    var a = $('.scroll-area>ul>li').slice(0,num);    $('.scroll-area>ul').animate({top:-height*num},1000,function(){$('.scroll-area>ul').append(a).css('top','0');});}$(document).ready(function(){    var interval = setInterval(function(){Scroll('40',1)},3000);})

In this example, the height of each row is 40px, and then the first li is converted to jquery variable a. After the ul is scaled up to 40px, the variable is appended to the end of ul, then convert ul's height to 0 (This section is not an animation)

I thought I still needed to delete the first li, but in fact it would automatically remove the dom variable or jQuery variable from the original location and put it in the new location.

Now that we understand this small feature and use the appand and prepend methods for convenience, it is much more convenient for those page effects that automatically rotate and scroll.

I am a newbie. After all, I found this feature for the first time.

 

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.