Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 17 09:32
    User @bjorno43 unbanned @linkin-park
  • Jun 20 21:19
    @bjorno43 banned @shenerd140
  • Apr 25 17:13
    @mstellaluna banned @cmal
  • Jan 08 22:05
    @mstellaluna banned @dertiuss323
  • Nov 07 2018 04:42
    User @texas2010 unbanned @ows-ali
  • Nov 02 2018 16:25
    @texas2010 banned @ows-ali
  • Oct 12 2018 05:50
    @bjorno43 banned @NACH74
  • Oct 05 2018 23:02
    @mstellaluna banned @JomoPipi
  • Sep 16 2018 12:21
    @bjorno43 banned @yash-kedia
  • Sep 16 2018 12:16
    @bjorno43 banned @vnikifirov
  • Sep 05 2018 08:12
    User @bjorno43 unbanned @androuino
  • Sep 05 2018 07:38
    @bjorno43 banned @androuino
  • Aug 23 2018 16:57
    User @bjorno43 unbanned @rahuldkjain
  • Aug 23 2018 16:23
    @bjorno43 banned @rahuldkjain
  • Jul 29 2018 14:13
    User @bjorno43 unbanned @jkyereh
  • Jul 29 2018 01:00
    @bjorno43 banned @jkyereh
  • Jul 10 2018 22:09
    @bjorno43 banned @manafn
  • Jul 06 2018 15:20
    @texas2010 banned @imlegend19
  • Jul 03 2018 12:28
    @bjorno43 banned @vbvmatta
  • Jun 29 2018 13:54
    @bjorno43 banned @OGTechnoBoy
Dardan Demiri
@dardandmr

@latimercaleb Whenever you want to see this image sent by @gulsvi

Just pres Ctrl+Shift+M

Gulsvi
@gulsvi
@NikolaNbgd can you check if an element has been populated with API data and conditionally call getApi() based on that?
if(!$("#myElement").text().trim().length) getApi();
NikolaNbgd
@NikolaNbgd
@dardandmr well, nothing happens, my data even aren't loaded
Dardan Demiri
@dardandmr
Can you put the whole code in Codepen
@NikolaNbgd here see an example
with jQueyr
jQuery
NikolaNbgd
@NikolaNbgd
@gulsvi yeah, but my div is empty until user scroll to desired section
Gulsvi
@gulsvi
@NikolaNbgd Right, so when it is no longer empty, no need to call the api. Or, set a flag to determine if the API has been called:
var api = false;

$(document).ready(function() {
  $(window).on("scroll", function() {
    var hT = $(".forks_me").offset().top,
      hH = $(".forks_me").outerHeight(),
      wH = $(window).height(),
      wS = $(this).scrollTop();
    if (wS > hT + hH - wH) getApi();
  });
});

function getApi() {
  if (!api) console.log("works");
  api = true;  
}
Run that code and you'll see "works" once in the console, instead of it appearing multiple times every time the user scrolls
NikolaNbgd
@NikolaNbgd
@dardandmr oh, need a week to put all my code in codepen, its a really big project, can we find some other solution? :/
Dardan Demiri
@dardandmr

Can you please explain this in more details:

I made it, but my API is called each time around when user scroll in that area.

NikolaNbgd
@NikolaNbgd
@gulsvi that make sense, but getApi is already function which displayed me data to the page, can't use function getApi() { if (!api) console.log("works"); api = true; }
Gulsvi
@gulsvi
@NikolaNbgd Without the code, we're playing pin the tail on the donkey. You'll need to figure out how to determine if your API has been called yet or not.
Or... share the code :)
@dardandmr I get an alert "Bottom" every time I scroll to that section - I think the goal is to only fire the alert (aka, call the api) once
Maybe I'm misunderstanding the goal though, tbh
Dardan Demiri
@dardandmr
$(document).ready(function () {
 var apiCall = true;
    $(window).on('scroll', function () {
        var hT = $('.forks_me').offset().top,
            hH = $('.forks_me').outerHeight(),
            wH = $(window).height(),
            wS = $(this).scrollTop();
        if (wS > (hT + hH - wH) && window.location.pathname == '/') {
            if(apiCall){
               getApi();
            }
            apiCall = false;
            console.log('works')
        }  
    })
});
This fires once in a lifetime
:P
@NikolaNbgd
Try this
it's your code just with the One Time call
Matthew
@RoutinePoutine
Why does myArray.slice(0, 4); result in the first four entries rather than the first five?
Dardan Demiri
@dardandmr
var a = ['zero', 'one', 'two', 'three'];
var sliced = a.slice(1, 3);

console.log(a);      // ['zero', 'one', 'two', 'three']
console.log(sliced); // ['one', 'two']
NikolaNbgd
@NikolaNbgd
@dardandmr yeeeep, that is my solutuon! :) thank you man!
CamperBot
@camperbot
nikolanbgd sends brownie points to @dardandmr :sparkles: :thumbsup: :sparkles:
:cookie: 284 | @dardandmr |http://www.freecodecamp.org/dardandmr
Dardan Demiri
@dardandmr
;)
@RoutinePoutine
var a = ['zero', 'one', 'two', 'three'];
var sliced = a.slice(1, 3);

console.log(a);      // ['zero', 'one', 'two', 'three']
console.log(sliced); // ['one', 'two']
This is how slice works
Matthew
@RoutinePoutine
If 0 is 1, why isn’t 3 ...4?
Thanks for the response
Dardan Demiri
@dardandmr

because the slice() function

takes 2 arguments

First one is where to start,

The second one is where to stop

Matthew
@RoutinePoutine
It only cuts first and last ?
Why not stop at 3? If 3 is 4?
Does the second argument happen after 0 is no longer 1?
Dardan Demiri
@dardandmr
can you make an example

like this

[1,2,3,4,5,6].slice(1,2)

Matthew
@RoutinePoutine
function findLength(array)
Dardan Demiri
@dardandmr
yes ?
Matthew
@RoutinePoutine
return array.length;
Sorry
I mean functionFourItems(array)
Dardan Demiri
@dardandmr
yes
Matthew
@RoutinePoutine
return array.slice(0, 4);
Dardan Demiri
@dardandmr
it should return just 4 items right ?
Matthew
@RoutinePoutine
I thought it would be 0, 3
Yes