简体   繁体   中英

random div position on load + draggable

I tried to create a code showing a draggable div on a random position. Page background picture is set to fit the size, this is the only thing almost quite working also with the fullscreen window function showing on clicking the links in the div. I guess I'm wrong on something (some syntax probably..) but can't find where it fails.

I show the lines on shrib, please open it: SHRIB notepad , i'm sure this would be easy to spot the mistakes for some of your fresh eyes:

thanks for your help!

J.

Your each function needs to be inside your document ready function.

<script type="text/javascript">
  $(document).ready(function() {
    $(".draggable").draggable();

$('.draggable').each(function(i,el){

    var tLeft = Math.floor(Math.random()*500),
        tTop  = Math.floor(Math.random()*500);

    $(el).css({position:'absolute', left: tLeft, top: tTop});

});
});

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM