items_03

In this example below you will see how to do a items_03 with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by crealime, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright crealime ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>items_03</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  
<div class="all">
  <div class="item-sm"></div>
  <div class="item-sm"></div>
  <div class="item-sm"></div>
  <div class="item-md"></div>
  <div class="item-sm"></div>
  <div class="item-sm"></div>
  <div class="item-sm"></div>
  <div class="item-sm"></div>
  <div class="item-md"></div>
  <div class="item-sm"></div>
  <div class="item-sm"></div>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/crealime/items_03-vxabKO */
.all {
  display: flex;
  flex-wrap: wrap;
}

.item-sm, .item-md {
  width: 23%;
  height: 100px;
  background: #ccc;
  margin: 1%;
}

.item-md {
  width: 48%;
}


/*Downloaded from https://www.codeseek.co/crealime/items_03-vxabKO */
var items = $('.all > div'),
widthAll = $('.all').width(),
item,
widthItem,
counter = 0,
widthCounter = 0;

function trans() {
	for(var i = 0; i < items.length; i++) {
		item = $(items[i]);
		widthItem = item.width();
		counter++;
		widthCounter += widthItem;
		// alert(widthCounter);
		
		if(counter == 2 && widthCounter > widthAll*.8) {
			// alert('2');
			counter = 0;
			widthCounter = 0;
		}
		else if (counter == 3 && widthCounter > widthAll*.7 && widthCounter < widthAll*.95) {
			// alert('3');
			counter = 0;
			widthCounter = 0;
		}
		else if (counter == 3 && widthCounter > widthAll) {
			// alert('3>');
			$(items[i+1]).after(item);
			counter = 0;
			widthCounter = widthItem/2;
		}
		else if(counter == 4 && widthCounter < widthAll) {
			// alert('4');
			counter = 0;
			widthCounter = 0;
		} else if(counter == 4 && widthCounter > widthAll) {
			// alert('4>');
			$(items[i+1]).after(item);
			counter = 0;
			widthCounter = widthItem/2;
		}
	}
	
}

trans();

Comments