javascript - 模拟瀑布流滚动,有一个小Bug
伊谢尔伦
伊谢尔伦 2017-04-11 09:09:14
[JavaScript讨论组]

bug鼠标向下滑一直可以加载,但向上滑一下就不继续加载了?这是为什么?
还有如何让动画更好看一点
需要把浏览器缩小出现竖向滚动条才能看到效果!

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<style>
    *,p,ul,li{
        margin:0;
        padding: 0;
        list-style: none;
    }
    
    ul{
        margin:0 auto;
    }
    li{
        height:30px;
        line-height: 30px;
        width:100px;
        border:1px solid red;
        border-radius: 5px;
        text-align: center;
        margin-bottom:5px;
    }
    li:nth-child(odd){
        background-color: #ccc;
    }
    .donghua{
        animation: move 1s ease;
        animation-fill-mode:forwards; 
        transform: translateY(100%) scale(.8);

    }
    @keyframes move{
        0%{
            transform: translateY(100%) scale(.8);
        }
        100%{
            transform: translateY(0%) scale(1);
        }
    }
</style>
<body>
    <p class="content">
        <ul class='list'>
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
            <li>6</li>
            <li>7</li>
            <li>8</li>
            <li>9</li>
            <li>10</li>
        </ul>
    </p>
</body>
<script src='../common/js/jquery.js'></script>
<script>
    window.onscroll=function(){
    var scrollTop=document.body.scrollTop;
    var client=document.documentElement.clientHeight;
    var heightAll=document.body.scrollHeight;
        if(scrollTop+client>=heightAll){
            var  lastLi=$("ul li:last-child");
            console.log(lastLi)
                 liVal=parseInt(lastLi.text())+1;
                 // console.log(parseInt(liVal)+1);
                 liClone=lastLi.clone().text(liVal);
                 console.log(liClone.text());
            $(".list").append(liClone);
            $("ul li:last-child").addClass('donghua');
        }
    }
</script>
</html>
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

全部回复(1)
大家讲道理

clone()会复制class,把下面这句去掉就行了。。。这加class的时机不对

// $("ul li").last().addClass('donghua');

其他的自己应该能解决。。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号