1

I am trying to get fastclick.js to work for me in order to get rid of the delay of 300ms when clicking. For some reason, this is not working for me. I will show all of my steps taken in order to reproduce the problem. I would truly appreciate someone to tell me where I've gone wrong. Thank you!

  1. Download fastclick.js by clicking "download zip"

  2. Extract zip file into my project

  3. Add <script type='application/javascript' src='fastclick.js'></script>

  4. Then, add the following code:

    if ('addEventListener' in document) {
        document.addEventListener('DOMContentLoaded', function() {
            FastClick.attach(document.body);
        }, false);
        }
    
  5. Finally, run the project, and notice that the console says "FastClick is not defined", and that the 300ms problem still persists

Thank you for your time. I would appreciate if someone went through the steps of including fastclick in javascript code.

gyre
  • 16,369
  • 3
  • 37
  • 47
Assafi Cohen-Arazi
  • 837
  • 10
  • 30

1 Answers1

1

I'm assuming you add the scripts in the wrong order. Make sure <script type='application/javascript' src='fastclick.js'></script> is before your <script type='application/javascript' src='main.js'></script>.

I use the filename main.js to signify the javascript file that holds your code. You might have given it a different name like, myJavascriptFile.js.

<html>
  <script type='application/javascript' src='fastclick.js'></script>
  <script type='application/javascript' src='main.js'></script>
</html>

If this doesn't work then you probably have the wrong path to source. All the files should be in the same folder or you need to change the src path.

EDIT:

Here's an example index.html file.

<html>
<body>
  <div id="Console"></div>

  <!--<script type='application/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js'></script>-->
  <script type='application/javascript' src='https://cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.js'></script>
  <script>
    if ('addEventListener' in document) {
      document.addEventListener('DOMContentLoaded', function() {
        FastClick.attach(document.body);
      }, false);
    }

    // TEST: Print FastClick function to the div.
    var consoleDiv = document.getElementById("Console");
    consoleDiv.innerText = FastClick.toString();
  </script>
</body>
</html>
christo8989
  • 6,442
  • 5
  • 37
  • 43