Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Need help in generating blocks with for loop

  • This topic is empty.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #46251
    Kuzyo
    Participant

    Hi guys

    Try to write a little game in JS using jQuery and I have to generate blocks with js can somebody give me advice how I can do it? Thanks for any help. Have to look something like this http://codepen.io/Kuzyo/pen/zhJxH

    #142012
    Malgosia
    Participant

    Hi!
    http://codepen.io/anon/pen/cqrxm
    To create new element I used document.createElement method.
    After that should set property className to “bricks”
    end on the end append new element to relevant conteinter, in your case #field div.

    One thing makes me curious. Why the margin of first (not added) elements is bigger than set (1px?)
    Someone know?

    #142022
    Kuzyo
    Participant

    Thanks @Malgosia appreciate your help. I remove **display: inline-block;** and added **float: left:** to .bricks looks better.http://codepen.io/Kuzyo/pen/zhJxH

    #142091
    Malgosia
    Participant

    So it wasn’t you want to accomplish, right?
    Maybe, you tell more about your project to help better understand your problem?

    #142188
    Kuzyo
    Participant

    Thanks, everything fine. Here some result, but game don’t get action yet http://jsbin.com/ibufux/3 Do you understand what I’m going to achive?

    #142447
    Malgosia
    Participant

    Ok, now I know what you want to accomplish :)
    And I think the better solution would be make bricks positioned absolute.
    Because after removing one of them, the rest would be still on the right place.

    See my codepen code. Perhaps you find it interesting and it help you.
    It is also without action function.

    http://codepen.io/pannafranka/pen/ipraJ

    #142663
    Kuzyo
    Participant

    Thanks for the help.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.