jQuery Scroll检测一次触发 [英] JQuery Scroll detection fire once

查看:61
本文介绍了jQuery Scroll检测一次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一小段JQuery,旨在折叠标题,更改其尺寸,然后将其粘贴到屏幕的一侧.这一切都离不开一部分,高度切换"功能每次用户滚动时都会触发,这确实很烦人.

I have a small piece of JQuery designed to collapse my header, change its dimensions, and then stick it to the side of the screen. It all works apart from one part, the height 'toggle' function fires every time the user scrolls, which gets really irritating.

有没有一种方法可以仅检测一次滚动或仅切换一次?

Is there a way I can detect scroll only once OR toggle only once?

$(window).scroll(function () {
var width = $(document).width() - 205;
var height = $(document).height();
  $('#me').animate({
    marginLeft: width,
    width: '22px',
    height: 'toggle',
    borderLeftWidth: "10px",
    borderRightWidth: "10px"    
  }, 1000, function() {
    $("#me:first").css("margin-top","-90px");
    var div = $('#me');
    $('#me h1').css("font-size","30px");
    var start = $(div).offset().top;
    $(div).css("height", height);
    $.event.add(window, "scroll", function() {
        var p = $(window).scrollTop();
        $(div).css('position',((p)>start) ? 'fixed' : 'static');
        $(div).css('top',((p)>start) ? '0px' : '');
    });
  });
});

推荐答案

查看jquery的one()功能 http://api.jquery .com/one/

look at jquery's one() functionality http://api.jquery.com/one/

它只会发射一次,然后立即将其自身移除.

It will only fire once and then promptly remove itself..

这篇关于jQuery Scroll检测一次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆