ember.js - Ember 2: How to add custom jQuery -
where following go?
$('a').click(function() { $('html, body').animate({ scrolltop: $($.attr(this, 'href')).offset().top }, 500); return false; });
i'm working in rails environment ember frontend inside rails app. tried in ember vendor's folder , called import in ember-cli-build.js, , when go test it, nothing works. missing step?
when add app.import
on ember-cli-build.js
make code part of vendor.js
file. vendor.js file downloaded , executed (to knowledge) before application available. meaning templates not rendered time code executed, , $('a')
return empty list (hence why it's not working).
if want believe may need event delegation, this:
$( "body" ).on( "click", "a", function() { $('html, body').animate({ scrolltop: $($.attr(this, 'href')).offset().top }, 500); return false; });
so delegate click events a
links when available in app.
the ember way of running code (jquery code) create component, i'm not sure trying achieve code.
Comments
Post a Comment