Random Movement in a Fixed Container

前端 未结 2 1305
死守一世寂寞
死守一世寂寞 2021-02-10 11:56

I\'m looking to create something that can move randomly inside of a fixed div container. I love the way the object moves in this example that I found searching this website...

2条回答
  •  借酒劲吻你
    2021-02-10 12:39

    Add a wrapper element around it and update the jQuery to limit the dimensions.

    // Get viewport dimensions (remove the dimension of the div)
        var h = $('#wrap').height() - 50;
        var w = $('#wrap').width() - 50;
    

    Here's an updated fiddle: http://jsfiddle.net/Xw29r/375/

提交回复
热议问题