jQuery: بحاجة إلى بعض المساعدة .. وظيفة رد الاتصال في .anive لا تعمل

StackOverflow https://stackoverflow.com/questions/816754

  •  03-07-2019
  •  | 
  •  

سؤال

أرغب في الحصول على نوع من التأثير المرتفع في البرنامج المساعد للرسوم المتحركة ولكنه لا يعمل. لا يسمى رد الاتصال على الإطلاق:

$(function() {
    var offset = $("#first").offset();
    var position = $(window).scrollTop();
    $(window).scroll(function() {
      var scroll = $(window).scrollTop();
      if (scroll>position) {
        $("body")
          .animate({
            scrollTop: offset.top + $("#first").innerHeight() + 150
          },
          1000,
          "easeInOutQuart",
          function() {
             $("body").animate({
              scrollTop: offset.top - 150
            },
            1000,
            "easeOutBounce"
            )
          })
      }
    })
  })

حسنًا .. ها هو رمز HTML الخاص بي .. لا أعرف لماذا يعمل لك بشكل رائع .. لكن لي ليس .. $ ('html') لا يعمل لكنك يعمل بشكل جيد ..

<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Bounce Test Pad</title>
<link rel=stylesheet href="index.css" type= "text/css" />
<script type="text/javascript" src ="jquery-1.3.2.js"></script>
<script type = "text/javascript" src="jquery.easing.1.3.js"></script>
</head>
<body>
    <img id="lightbulb" src = "img/veioza.png">
    <div id="wrapper">
        <img id="first"  class="images" src="img/nike.jpg" />
        <img id ="second" class = "images" src="img/golden.jpg" />
        <img id = "third" class ="images" src ="img/a.jpg" />
    </div>
<script type="text/javascript">
    $(window).resize(function() {
        centerIt();
    });
    $(function() {
        centerIt();
    })
    function centerIt() {
        var viewportWidthSize = window.innerWidth;
        var pixels = (viewportWidthSize / 2) - $("#first").width() / 2;
        $("#wrapper img").css("left",  pixels);
    };


    $(function() {
        var offset = $("#first").offset();
        var prevpos = $(window).scrollTop();
        var animating = false;
        $(window).scroll(function() {
            var curpos = $(window).scrollTop();
            if (curpos>prevpos && !animating) {
                $('html').animate(
                        {scrollTop: offset.top + $("#first").height()},
                        1000,
                        "easeInOutQuart"
                    )
            }
            animating = true;
        })
    })
</script>
</body>
</html>
هل كانت مفيدة؟

المحلول

Anhtu محق في الرسوم المتحركة التي تثير حدث التمرير.

هذا العرض التوضيحي الثابت: http://jsbin.com/alede (يمكنك تعديل العرض التوضيحي هنا: http://jsbin.com/alede/edit)

يجب عليك إضافة رمز لمنع إعادة التثبيت أثناء حدوث الرسوم المتحركة:

var status = $('#status');
var offset = $("#downcontent").offset();
var height = $("#downcontent").height();
var animating = false;
var prevpos = $(window).scrollTop();

$(window).scroll(function(){
  var curpos = $(window).scrollTop();
  if (curpos > prevpos && !animating) {
    $('html').animate(
      {scrollTop: offset.top + height},
      1000,
      "easeInOutQuart",
      function(){
        $('html').animate(
          {scrollTop: offset.top},
          1000,
          "easeOutBounce",
          function(){
            animating = false;
            status.html('Both animations finished.<br />');
          }
        );
        status.html('First animation finished.<br />Second animation started<br />');
      }
    );
    animating = true;
    status.html('First animation started<br />');
  }
  prevpos = curpos;
});

يحرر

حسنًا ، لقد قمت بإنشاء عرض توضيحي آخر مع رمز HTML الخاص بك. لقد أصلحت JavaScript قليلاً وأضفت بعض قواعد CSS: http://jsbin.com/oqapa

نصائح أخرى

افعل ذلك دون استخدام رد الاتصال

if (scroll>position) {
    $("body")
      .animate({
        scrollTop: offset.top + $("#first").innerHeight() + 150
      },1000,"easeInOutQuart")
      .animate({
        scrollTop: offset.top - 150
      },1000,"easeOutBounce")
    })
 }

لكنني أعتقد أنك هافا لربط حدث آخر. لأنه عند تحريك الجسم ، قد يرفع نافذة الحدث.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top