Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I send through variable from function to nested function
    primarykey
    data
    text
    <p>As a javascript noob I have some trouble understanding how I can get variables from a function to another in the supplied example.</p> <p>I want to use winHeight that is set in <code>xx.projects.resize</code> in <code>xx.projects.item.next</code> (you see the console.log(winHeight) in there).</p> <p>What should I be looking at here?</p> <pre><code>var xx = { init: function() { xx.listener.init() }, listener: { init: function() { xx.listener.resize() }, resize: function() { xx.projects.resize() $(window).on('resize',function(){ xx.projects.resize() }) }, }, projects: { resize: function() { var $display = $('section .item.curr'); var $displayNotActive = $('section.curr .item.next, section.curr .item.prev'); var winWidth = $(window).width(); var winHeight = $(window).height(); var containerWidth, containerHeight; if(winWidth &gt; 1450) { if(winHeight &gt; 1050) { containerWidth = 1200; containerHeight = 900; } else { containerWidth = winWidth - 250; var helperHeight = Math.floor(containerWidth * 3/4); if(helperHeight &gt; (winHeight - 150)) { containerHeight = winHeight - 150; containerWidth = Math.floor(containerHeight * 4/3); } else { containerHeight = helperHeight; } } } else if(winWidth &lt; 600) { containerWidth = 300; containerHeight = 225; } else { containerWidth = winWidth - 250; var helperHeight = Math.floor(containerWidth * 3/4); if(helperHeight &gt; (winHeight - 150)) { containerHeight = winHeight - 150; containerWidth = Math.floor(containerHeight * 4/3); } else { containerHeight = helperHeight; } } }, item: { next: function() { var s = $('#projects section.curr') a = s.find('.item.curr'), n = a.next('.item'), l = a.position() console.log(winHeight); if( n.length &gt; 0 ){ a.animate({ left: '-100%' }, ep.projects.config.item.speed, ep.projects.config.item.easing) n.animate({ left: l.left }, ep.projects.config.item.speed, ep.projects.config.item.easing, function(){ a.removeClass('curr').addClass('prev') n.removeClass('next').addClass('curr') }) } }, }, } } $(document).on('ready', xx.init) // Document loaded, DOM ready </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload