Overlay testing.
Last active
November 14, 2016 16:29
-
-
Save dephora/6c38e73c5b1f63f8173a8c1b38ce34df to your computer and use it in GitHub Desktop.
Overlay Factory - Buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.box | |
.box1.shadow | |
.box2.shadow | |
.box3.shadow | |
.box4.shadow | |
.box5.shadow | |
.box2.shadow | |
.box3.shadow | |
.flex-container | |
%button.btn | |
Overlay it | |
%button.btn.btn-clear | |
Clear All | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="box"> | |
<div class="box1"></div> | |
<div class="box2"></div> | |
<div class="box3"></div> | |
<div class="box4"></div> | |
<div class="box5"></div> | |
<!-- <button class="btn">Overlay It</button> | |
<button class="btn btn-clear">Clear All</button> --> | |
<h3>Click an element to create an overlay around it, press any key to clear the overlays. The overlays will not clear until you hit a key and will continue to stack until you do.</h3> | |
</div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var createOverlays = function(ev) { | |
// console.log(this) | |
// console.log(ev); | |
var $mainContainer = $(".box"); | |
var $mainContainerWidth = $mainContainer.outerWidth(); | |
var $mainContainerHeight = $mainContainer.outerHeight(); | |
var $target = $(".box2"); | |
var $targetWidth = $target.outerWidth(); | |
var $targetHeight = $target.outerHeight(); | |
var $targetOffset = $target.offset(); | |
var $targetOffsetTop = $target.offset().top; | |
var $targetOffsetLeft = $target.offset().left; | |
/******************* TOP OVERLAY ******************/ | |
function createTopOverlay() { | |
var overlayProps = { | |
"height": $targetOffsetTop, | |
"class": "topOverlay" | |
}; | |
overlayFactory(overlayProps); | |
}; | |
/***************** BOTTOM OVERLAY ****************/ | |
function createBottomOverlay() { | |
var overlayTop = $targetOffsetTop + $targetHeight; | |
var overlayHeight = ($mainContainerHeight - $targetOffsetTop - $targetHeight); | |
var overlayProps = { | |
"height": overlayHeight, | |
"top": overlayTop, | |
"class": "bottomOverlay" | |
}; | |
overlayFactory(overlayProps); | |
}; | |
/****************** LEFT OVERLAY *****************/ | |
function createLeftOverlay() { | |
var overlayHeight = $targetHeight; | |
var overlayWidth = $targetOffsetLeft; | |
var overlayTop = $targetOffsetTop; | |
var overlayProps = { | |
"height": overlayHeight, | |
"top": overlayTop, | |
"width": overlayWidth, | |
"class": "leftOverlay" | |
}; | |
overlayFactory(overlayProps); | |
}; | |
/****************** RIGHT OVERLAY *****************/ | |
function createRightOverlay() { | |
var overlayLeft = $targetOffsetLeft + $targetWidth; | |
var overlayTop = $targetOffsetTop; | |
var overlayHeight = $targetHeight; | |
var overlayWidth = ($mainContainerWidth - $targetWidth - $targetOffsetLeft); | |
var overlayProps = { | |
"height": overlayHeight, | |
"top": overlayTop, | |
"width": overlayWidth, | |
"left": overlayLeft, | |
"class": "rightOverlay" | |
}; | |
overlayFactory(overlayProps); | |
}; | |
/****************** OVERLAY FACTORY *****************/ | |
function overlayFactory(overlayProps) { | |
var overlayDiv = $('<div />', { | |
"class": 'tourOverlay ' + overlayProps.class, | |
"data-label": 'tourOverlay', | |
"height": overlayProps.height, | |
"width": overlayProps.width | |
}); | |
overlayDiv.css("top", overlayProps.top || 0) | |
overlayDiv.css("left", overlayProps.left || 0) | |
$('body').append(overlayDiv); | |
}; | |
/*********************** INIT **********************/ | |
function init() { | |
createTopOverlay(); | |
createBottomOverlay(); | |
createLeftOverlay(); | |
createRightOverlay(); | |
} | |
return init(); | |
}; | |
function clearOverlays() { | |
$( '[data-label="tourOverlay"]' ).remove(); | |
} | |
window.onresize = function(){ | |
clearOverlays() | |
createOverlays(); | |
} | |
$('.btn').on('click', createOverlays); | |
$('.btn-clear').on('click', clearOverlays); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/paper.js/0.10.2/paper-full.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0 !important; | |
font-family: Lato; | |
letter-spacing: 1px; | |
line-height: 1.5; | |
font-weight: 300 !important; | |
} | |
.box > *:not(:first-child) { | |
margin-top: 30px !important; | |
} | |
h3, | |
p { | |
margin-top: 50px; | |
padding: 10px 60px 0; | |
text-align: center; | |
} | |
p { | |
margin-top: 0; | |
} | |
.box { | |
height: 100vh; | |
color: white; | |
background: linear-gradient(to left, #4776E6, #8E54E9); | |
} | |
.shadow { | |
box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25), 0 10px 10px rgba(0, 0, 0, 0.22); | |
} | |
.box1, | |
.box3 { | |
height: 40px; | |
background: rgb(255, 255, 0); | |
margin: auto; | |
position: relative; | |
z-index: 11; | |
} | |
.box3 { | |
height: 70px !important; | |
background: rgb(24, 255, 255); | |
} | |
.box2 { | |
width: 300px; | |
height: 40px; | |
background: rgb(255, 82, 82); | |
margin: 5px auto; | |
position: relative; | |
z-index: 11; | |
} | |
.flex-container { | |
display: flex; | |
flex-direction: row; | |
align-items: center; | |
justify-content: center; | |
} | |
.btn { | |
flex: center; | |
margin-top: 40px; | |
height: 50px; | |
width: 100px; | |
background: rgb(178, 255, 89); | |
color: black; | |
font-size: 1rem; | |
box-shadow: 0 14px 28px rgba(0,0,0,0.25), 0 10px 10px rgba(0,0,0,0.22); | |
border: none; | |
margin-right: 10px; | |
/* margin-left: auto; */ | |
} | |
.box4 { | |
background: rgb(213, 0, 249); | |
width: 50vw; | |
height: 6vw; | |
margin-top: 20px; | |
} | |
.box5 { | |
background: rgb(178, 255, 89); | |
width: 50vw; | |
height: 6vw; | |
margin-top: 20px; | |
margin-left: auto; | |
} | |
.btn.btn-clear { | |
background: rgb(255, 82, 82) !important; | |
} | |
.tourOverlay { | |
pointer-events: none; | |
} | |
.topOverlay, | |
.bottomOverlay, | |
.rightOverlay, | |
.leftOverlay { | |
z-index: 1000; | |
position: absolute; | |
background: rgba(0, 0, 0, .5); | |
} | |
.bottomOverlay, | |
.topOverlay { | |
width: 100%; | |
left: 0; | |
} | |
.leftOverlay { | |
left: 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment