手动触发DOM元素的滚动事件? [英] Manually trigger a scroll event of DOM element?

查看:857
本文介绍了手动触发DOM元素的滚动事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立的Web元素,如果我滚动一个元素的内容,我也希望同时滚动第二个元素.这是一个示例: https://stackedit.io

I have two independent web elements, if I scroll the content of one element, I also want the 2nd element scroll at same time. Here is an example: https://stackedit.io

我做了下面的代码,但是没有用:

I did the following code, but it is not working:

element.find('.fullscreen-mk-content-textarea').on('scroll', function(e){
    // first element will trigger this event, then manully trigger the 
    // the scroll of the 2nd element. It's my plan. 
    console.log(e); // works
    element.find('.right-side').trigger('scroll'); // doesn't work...
});

我该怎么办?

推荐答案

尝试以下 jsFiddle .

$('.e1').scroll(function(e){
    $('.e2').scrollTop(parseInt($('.e1').scrollTop()));
});

这篇关于手动触发DOM元素的滚动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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