Jquery's animate makes the two div scroll naturally.

topic description

use jquery"s animate, to stack two div on top of each other, click the button to run up, and you can see that their junction scrolls very inelegantly. The picture does not show that the code can be copied locally.

sources of topics and their own ideas

related codes

/ / Please paste the code text below (do not replace the code with pictures)


< html >

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <style type="text/css">
        .father{
            
            margin-top: 200px;
            margin-bottom: 200px;
        }
        .son1{
            width: 100px;
            height: 100px;
            background-color: red;
            position: relative;
        }
        .son2{
            width: 100px;
            height: 100px;
            background-color: green;
            position: relative;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son1"></div>
        <div class="son2"></div>
    </div>
    <button></button>
</body>
<script type="text/javascript">
    $("button").click(function(){
        $(".son1").animate({top:-100},500);
        $(".son2").animate({top:-100},500);
    })
</script>

< / html >

what result do you expect? What is the error message actually seen?

how to make the two div scroll up naturally to solve the problem at the junction

Apr.11,2021

first, why not use parent to scroll, which is much better than two son scrolling themselves. Second: transition will be more appropriate, you can try to see if there is a natural point

<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>
    <style type="text/css">
        .father{
            position: relative;
            margin-top: 200px;
            margin-bottom: 200px;
            transition: 0.5s top linear;
            top: 0;
        }
        .son1{
            width: 100px;
            height: 100px;
            background-color: red;
        }
        .son2{
            width: 100px;
            height: 100px;
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="son1"></div>
        <div class="son2"></div>
    </div>
    <button></button>
    <script type="text/javascript">
        $("button").click(function(){
            $(".father").css({top:-100},500);
        })
    </script>
</body>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b352c5-34321.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b352c5-34321.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?