Reputation: 6749
I'm trying to target the scroll event for both the window and scrollable divs. Is there a way to do this in one statement?
I've tried...
$(window, '.box-scroll').scroll(function() { });
Only way I have found is calling them both separately...
$(window).scroll(function() { });
$('.box-scroll').scroll(function() { });
Upvotes: 0
Views: 109
Reputation: 64657
There may be a better way to do this, but you could use $.map to create a jquery object with both window and .boxscroll, like so:
var $d = $($.map([$(window), $('.boxscroll')], function(el){return $.makeArray(el)}));
$d.on('scroll', function() { ... });
EDIT: $(window).add('.box-scroll').scroll(function() { });
Upvotes: 1
Reputation: 2374
Fiddled with it for a while but can't see any reason it wouldn't.
I can suggest a workaround at best, in case you just need a single function.
$(window).scroll(function(){scroller('a');});
$('.box-scroll').scroll(function(){scroller('b');});
function scroller(source){$('.box-scroll-inside').html('scrollling'); };
Upvotes: 0