Share Posted September 16, 2017 Hi, is there a way to use the gsap Draggable in Nuxt.js? I get the error "navigator is not defined" in file "node_modules\gsap\Draggable.js" line 391 _isIE10orBelow = (((/MSIE ([0-9]{1,}[\.0-9]{0,})/).exec(navigator.userAgent) || (/Trident\/.*rv:([0-9]{1,}[\.0-9]{0,})/).exec(navigator.userAgent)) && parseFloat( RegExp.$1 ) < 11), //Ideally we'd avoid user agent sniffing, but there doesn't seem to be a way to feature-detect and sense a border-related bug that only affects IE10 and IE9. I am referencing gsap and Draggable inside my .vue file by: import TweenMax from 'gsap' import Draggable from 'gsap/Draggable' I am guessing this is due to Nuxt doing a server side render and not having a window/navigator object? Link to comment Share on other sites More sharing options...
Share Posted September 16, 2017 Yep. Did you look at this? https://nuxtjs.org/faq/window-document-undefined/ 2 Link to comment Share on other sites More sharing options...
Author Share Posted September 16, 2017 @OSUblake Thanks for that, I finally figured it out. I added it within the mounted function <script> import TweenMax from 'gsap' export default { data () { return { } }, mounted () { if (process.browser) { const Draggable = require('gsap/Draggable') Draggable.create('.scrubber__blob', { type: 'x', bounds: '.scrubber', onDrag () { let perc = this.endX / this.maxX * 100 perc = Math.floor(perc) + '%' console.log(perc) } }) } } } </script> I wonder if this is the proper way to import components and/or other libraries as they all seem to be at the top just after the opening the <script> tags Link to comment Share on other sites More sharing options...
Share Posted September 16, 2017 Hi @aderon14 I think that's fine, but I'm no expert. For that, I would highly recommend following Sarah Drasner. She does a bunch of workshops and presentations on GSAP and Vue/Nuxt. GitHub - a bunch of good stuff in here https://github.com/sdras?tab=repositories CodePen See the Pen public by sdras (@sdras) on CodePen Twitter https://twitter.com/sarah_edo Slides http://slides.com/sdrasner 5 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now