Skip to content

Instantly share code, notes, and snippets.

@wwwisie
Created February 27, 2020 21:06
Show Gist options
  • Select an option

  • Save wwwisie/ca3151dc40d1a2d4c3e9a5adaa5b5d6e to your computer and use it in GitHub Desktop.

Select an option

Save wwwisie/ca3151dc40d1a2d4c3e9a5adaa5b5d6e to your computer and use it in GitHub Desktop.
Random Coordinate Emoji Placement on Images
<div id="parallax-container">
<% @inicio_gallery.assets.each_slice(12).with_index do |slice, index| %>
<div class="parallax" id="parallax-lvl-<%= index %>">
<% slice.each_with_index do |asset, i| %>
<div class="<%= @gallery_array[i % 3] %> rellax img-wrap" data-rellax-speed="<%=rand(3)%>">
<img src="<%= asset.asset.url %>">
<div class="absolute-wrap">
</div>
</div>
<% end %>
</div>
<% end %>
</div>
section.bg-off .parallax {
padding-top: 100px;
// margin-bottom: -600px;
max-width: 1500px;
margin: 0 auto;
transform-style: preserve-3d;
@media(min-width:992px) {
& .img-wrap {
padding: 0;
font-size: 80px;
position: relative;
width: 50%;
max-width: 1000px;
max-height: 300px;
}
}
// &#parallax-lvl-1, &#parallax-lvl-2, &#parallax-lvl-3 {
// margin-top: -800px;
// }
&-left {
left:15px;
}
&-center {
left:0;
right:0;
margin: 0 auto;
display: block;
}
&-bottom {
margin: 0 auto;
display: block;
transform: scale(0.7);
right: -30%;
}
&-right {
right: -45%;
}
@media(max-width:992px) {
padding: 0px 15px 0;
&#parallax-lvl-1, &#parallax-lvl-2, &#parallax-lvl-3 {
// margin-top: -400px;
}
&-left {
left:0;
right: 0;margin-right:auto; display: block;
top: -250px !important;
width: 60%;
position: relative;
}
&-center {
left:0;
right: 0;margin: 0 auto; display: block;
top:0px !important;
width: 70%;
position: relative;
}
&-right {
left:0;
right: 0;margin-left:auto; display: block;
top:0px !important;
width: 50%;
position: relative;
}
&-bottom {
left:0;
display: block;
top: -400px !important;
width: 70%;
right: 20%;
margin: 0 0 0 auto;
position: relative;
}
&#parallax-lvl-0 {
padding: 100px 0 0;
}
}
@media(max-width:767px) {
padding: 100px 15px 0;
&#parallax-lvl-1, &#parallax-lvl-2, &#parallax-lvl-3 {
// margin-top: 0px;
padding-top: 0;
}
&#parallax-lvl-0 {
.parallax-left {
top:-10px;
}
.parallax-bottom {
top:0px;
right: 0%;
}
}
}
}
; (function (window, document, undefined) {
"use strict";
var init = function () {
var canvasImg = document.querySelector('.img-wrap img');
var absWrap = document.querySelector('.absolute-wrap')
var icon_template = document.querySelector('#template');
var icon_width = 40;
var icon_height = 30;
var total_number_of_images = 50;
var max_height = canvasImg.offsetHeight - icon_height;
var max_width = canvasImg.offsetWidth - icon_width;
var randomCoordinate = function () {
var r = [];
var x = Math.floor(Math.random() * max_width);
var y = Math.floor(Math.random() * max_height);
r = [x, y];
return r;
};
var createImage = function () {
var node = icon_template.cloneNode(true);
var xy = randomCoordinate();
node.removeAttribute('id');
node.removeAttribute('hidden');
node.style.top = xy[1] + 'px';
node.style.left = xy[0] + 'px';
node.textContent = '🌶'
// node.setAttribute('src', pickRandomImage());
absWrap.appendChild(node);
};
for (var i = 0; i < total_number_of_images; i++) {
createImage();
};
};
window.addEventListener('load', init);
})(window, document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment