0

我无法弄清楚如何将函数分配给 Dojo 中的滚动事件。我已经看过关于使用 dojo 连接的一篇文章,但我一直无法让它工作,即使我可以,我的项目也尽可能多地使用行为,所以我真的想先让它工作...

对我来说令人费解的是,我在 dojo 的网站上浏览了一下,而我看到的滚动事件的唯一参考只是将它们作为旁白提及。以http://dojotoolkit.org/reference-guide/1.9/quickstart/events.html#connecting-to-a-dom-event为例,有一个可以连接的事件列表,并且滚动是不在他们身上。鼠标滚轮向上 + 向下是,但这并不涵盖可能导致滚动发生的所有可能操作。

我以前使用过 jQuery 的滚动事件,这很简单。我在解决 Dojo 中的滚动事件时遇到了这么多麻烦,这让我有点困扰。

这是我尝试过的:

var myBehavior = {
    window : {
    scroll: function(e) {
        console.log("i'm scrolling");
        }
    }
    };
behavior.add(myBehavior);
behavior.apply();

加载没有任何问题,但滚动不会给我控制台日志消息。

我也试过

dojo.connect(window,'scroll',this,function() {
        console.log("scrolling away");
    })

我几乎是从链接的帖子中得到的,我也没有收到控制台日志消息。我开始怀疑我是否缺少密钥库?

我要求的那些我认为是多余的: - dojo/_base/lang - dojo/query - dojo/_base/event - dojo/on - dojo/behaviour - dojo/window

有人对我如何开始在 Dojo 中注册这些滚动事件有建议吗?谢谢

4

2 回答 2

2

我创建了一个jsfiddle 来演示窗口滚动事件的用法dojo/on

html:

<body>
    <div style="height:1000px;">
        Bacon ipsum dolor sit amet meatball drumstick jerky strip steak kielbasa shoulder, short ribs filet mignon prosciutto swine meatloaf ribeye tongue turkey andouille. Hamburger bacon fatback, short ribs pork loin cow chicken. Capicola venison andouille kielbasa cow. Short ribs kevin rump meatloaf jowl prosciutto leberkas. Pork belly shankle doner spare ribs, rump pork chop sausage tenderloin. Brisket swine pig, fatback beef ribs shank tri-tip flank ham venison strip steak filet mignon rump frankfurter ribeye.

Fatback turkey sausage tongue doner strip steak boudin shoulder chuck beef ribs chicken bacon brisket. Turkey biltong bacon cow short ribs fatback. Sausage brisket pork loin corned beef pork chop shank jowl capicola leberkas strip steak prosciutto beef tri-tip. Jowl frankfurter beef ribs, swine tail doner tri-tip t-bone. Jowl pork loin sausage venison salami shankle kevin strip steak boudin doner bresaola filet mignon ham drumstick ribeye. Turkey pork belly kielbasa ribeye salami, strip steak ham hock jerky shoulder tenderloin shankle spare ribs beef ribs filet mignon. Short loin fatback kevin, biltong tail shoulder ball tip.

Pork loin t-bone ground round tongue turducken tail shoulder chicken sausage pancetta hamburger, kielbasa tri-tip strip steak short ribs. Pork chop prosciutto tri-tip, jerky brisket leberkas andouille ham hock tongue shoulder fatback meatball. Pig short loin beef spare ribs, rump meatball short ribs doner kielbasa ball tip swine bacon kevin. Hamburger tail frankfurter ham hock tongue, jerky pork belly bacon shank salami prosciutto ground round doner jowl turducken. Prosciutto pork chop drumstick ham hock meatloaf. Drumstick ham hock ball tip salami cow.

Shankle hamburger sirloin sausage tongue pork chop flank, doner pig tri-tip pancetta shoulder. Venison ball tip beef biltong tail, corned beef pastrami andouille frankfurter kevin pork meatball chicken. Ground round shankle sirloin capicola kevin spare ribs ham hock fatback strip steak short ribs leberkas. Venison flank tenderloin tri-tip salami pork capicola drumstick brisket short ribs sirloin chuck boudin kielbasa cow.

Short ribs corned beef shankle meatball, tri-tip t-bone sirloin cow leberkas chicken jerky. Short loin drumstick pork loin biltong sausage prosciutto rump flank hamburger pork chop meatball capicola turkey leberkas cow. Andouille ribeye boudin ham chicken. T-bone rump meatball drumstick hamburger pork chop, flank sausage tongue andouille fatback.

Does your lorem ipsum text long for something a little meatier? Give our generator a try… it’s tasty!
    </div>
</body>

js:

require(['dojo/on','dojo/domReady!'],function(on,domReadyPlugin){

    on(window,'scroll',function(evt){
        console.log(evt);

    });
});

每次用户在窗口中滚动时,结果都会打印到控制台。如果您仍然遇到问题,请发布更多代码以便我们深入了解它,这应该是一件简单的事情。

于 2013-10-08T12:02:55.717 回答
0

使用“onscroll”而不是“scroll”,看到这个 jsfiddle

dojo.connect(window,'onscroll',this,function() {
        console.log("scrolling away");
    })
于 2013-10-06T16:03:52.400 回答