How do I put codes from jsfiddle.net into my website?

前端 未结 1 1861
心在旅途
心在旅途 2020-11-28 14:55

I’ve been trying to create a little box at the bottom of my webpage which will expand / pop-up when scrolled over and then close again when the mouse moves away.

I f

相关标签:
1条回答
  • 2020-11-28 15:24

    You are running this code immediately, rather than waiting for the DOM to be ready. This means that the element #box may not exist yet.

    jsFiddle automates this process to make your code cleaner. You need to do it yourself when you put the code into your own website. It is very easy: you just need to put your code into a callback to the ready event on the document:

    $(document).ready(function() {
        // put your Javascript here
    });
    

    or, a shortcut version:

    $(function(){
        // put your Javascript here
    });
    

    These are semantically and functionally equivalent.

    0 讨论(0)
提交回复
热议问题