實現滾動條滾動到指定位置時,滑入顯示某個元素


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        .test{
            margin:900px auto 500px;
            width:800px;
            height:600px;
            position: relative;
            background-color: #00ac61;
        }
        .target{
            position: absolute;
            left:200px;
            width:400px;
            height:300px;
            opacity: 0;
            background-color: palevioletred;
        }

    </style>
    <script src="./js/jquery-1.11.3.min.js"></script>
</head>
<body>
 
   <div class="test">
       <div class="target">
           test test test 
       </div>
   </div>
   <script>
       $(function(){
           var targetHeight = $(".test").offset().top;

           $(window).scroll(function(){
                slideIn($(".target"),150);
           });

          function slideIn(obj,left){
              var targetHeight = obj.offset().top;
              var scrollTop = $(this).scrollTop();
              if(scrollTop>targetHeight-400){
                   obj.animate({left:left+'px',opacity:1,filter:'Alpha(opacity=90)'},500);
              }
           };

       });
   </script>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM