$(window).load OR $(window).scroll在同一个函数中? [英] $(window).load OR $(window).scroll in the same function?

查看:92
本文介绍了$(window).load OR $(window).scroll在同一个函数中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网站上实现了stickyfloat(http://plugins.jquery.com/files/stickyfloat_0.htm)。它适用于一个问题。该函数在 $(窗口).scroll 上触发,而不在 $(窗口).load 上触发。我希望它能触发,因为我链接到页面中的锚点(http://tre-stage.wdogsystems.com:8000/faq/#does-the-sale-of-my-receivables-have-a - 我的信用报告上的负效应)我希望在页面加载时显示侧边菜单,而不仅仅是当我启动滚动时。

I have implemented stickyfloat (http://plugins.jquery.com/files/stickyfloat_0.htm) on a site. It works great with one gotcha. The function triggers on $(window).scroll and not on $(window).load. I want it to trigger on either because I am linking to anchor points in the page (http://tre-stage.wdogsystems.com:8000/faq/#does-the-sale-of-my-receivables-have-a-negative-effect-on-my-credit-report) and I would like the side menu to appear when the page loads and not just when I initiate a scroll.

如果你看一下上面的页面,它就像我想要的那样工作。但是,这只是因为我用 $(窗口).load 重复了相同的功能。这对我来说似乎非常低效。那么,有没有办法把两者连在一起?

If you look at the page above, it's working just as I want it to. However, this is only because I've repeated the same function with a $(window).load. This seems highly inefficient to me. So, is there a way to chain the two together?

例如:

$(window).scroll || $(window).load (function () ...


推荐答案

只是绑定在绑定中,如:

just chain in the bind, like:

$(window).bind("scroll load", ...)

然而附加滚动事件非常糟糕

however it is very bad idea to attach to scroll event

一个非常好的解释原因和一个很好的解决方案: http://ejohn.org / blog / learning-from-twitter /

a very good explanation why and a great solution: http://ejohn.org/blog/learning-from-twitter/

这篇关于$(window).load OR $(window).scroll在同一个函数中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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