My element wont position center - javascript
My element "#splashlogo" doesn't seem to want to centre in the body of my document.I have tried positions; absolute, relative, fixed etc. I'm not sure what is happening.
It may be something to do with other parts of my code...?
My HTML:
<html><head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="css/splashscreenstyle.css">
</head>
<body>
<script src="http://codepen.io/assets/libs/fullpage/jquery.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
//hiding initially
$('.scene').hide();
//Fade In and delay 2.5 sec then Fade Out
$('.splashscreenlogo').hide().fadeIn(function() {
$(this).delay(2500).fadeOut(function() {
//Fade In and delay 3 sec then Fade Out
$('.scene').fadeIn(function() {
$(this).delay(15000).fadeOut(function() {
//Redirect to any location
window.location = 'index.html';
});
});
});
});
});
window.onload = function() {
Animate(1);
Animate(2);
}
function Animate(number) {
var line = document.getElementById('movingLine' + number);
var lineLength = line.getTotalLength().toString();
var lineAnim = document.getElementById('lineAnim' + number);
line.setAttributeNS(null, 'stroke-dasharray', lineLength + " " + lineLength);
line.setAttributeNS(null, 'stroke-dashoffset', lineLength);
lineAnim.setAttributeNS(null, 'from', lineLength);
lineAnim.setAttributeNS(null, 'values', lineLength + ';0');
}
function fade(number) {
var line = document.getElementById('movingLine' + number);
var animation = document.createElementNS(
'http://www.w3.org/2000/svg', 'animate');
animation.setAttributeNS(null, 'attributeName', 'opacity');
animation.setAttributeNS(null, 'to', 0);
animation.setAttributeNS(null, 'dur', 3.25);
animation.setAttributeNS(null, 'begin', 10);
animation.setAttributeNS(null, 'fill', 'freeze');
line.appendChild(animation);
}
</script>
<h4></h4>
<div class="scene" style="display: none;">
<svg version="1.1" id="dc-spinner" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width:"38"="" height:"38"="" viewBox="0 0 38 38" preserveAspectRatio="xMinYMin meet">
<text x="14" y="21" font-family="Monaco" font-size="2px" style="letter-spacing:0.6" fill="grey">LOADING
<animate attributeName="opacity" values="0;1;0" dur="1.8s" repeatCount="indefinite"></animate>
</text>
<path fill="#2AA198" stroke="#ffffff" stroke-width="0.5027" stroke-miterlimit="10" d="M5.203,20
c0-8.159,6.638-14.797,14.797-14.797V5C11.729,5,5,11.729,5,20s6.729,15,15,15v-0.203C11.841,34.797,5.203,28.159,5.203,20z">
<animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" calcMode="spline" keySplines="0.4, 0, 0.2, 1" keyTimes="0;1" dur="2s" repeatCount="indefinite"></animateTransform>
</path>
<path fill="#859900" stroke="#ffffff" stroke-width="0.5027" stroke-miterlimit="10" d="M7.078,20
c0-7.125,5.797-12.922,12.922-12.922V6.875C12.763,6.875,6.875,12.763,6.875,20S12.763,33.125,20,33.125v-0.203
C12.875,32.922,7.078,27.125,7.078,20z">
<animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="1.8s" repeatCount="indefinite"></animateTransform>
</path>
</svg>
</div>
<div class="splashscreenlogo" style="display: block;">
</div>
<div class="canvas_container">
<svg width="100%" height="100%" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" version="1.1" baseProfile="full">
<g>
<path id="movingLine1" d="m 20,-10 l -20,600 z" class="white-line" stroke-dasharray="1200.66650390625 1200.66650390625" stroke-dashoffset="1200.66650390625">
<animate id="lineAnim1" attributeName="stroke-dashoffset" from="1200.66650390625" to="0" dur="5.5s" begin="9.5s" fill="freeze" values="1200.66650390625;0"></animate>
</path></g>
<g>
<path id="movingLine2" d="m 80,-10 l -20,600 z" class="white-line" stroke-dasharray="1200.66650390625 1200.66650390625" stroke-dashoffset="1200.66650390625">
<animate id="lineAnim2" attributeName="stroke-dashoffset" from="1200.66650390625" to="0" dur="5.5s" begin="10.5s" fill="freeze" values="1200.66650390625;0"></animate>
</path></g>
</svg>
</div>
<div id="splashlogo">
<img src="logo_splashscreen.png" alt="Splashscreen logo">
</div></body></html>
My CSS:
/* Demo Styles */
html {
height: 100%;
min-height: 100%;
overflow: hidden;
}
html body {
background: url("Splashscreen.png") no-repeat;
background-size: 100%;
font: 14px/21px Monaco, sans-serif;
color: none;
font-smoothing: antialiased;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
text-size-adjust: 100%;
height: 100%;
min-height: 100%;
}
html body a, html body a:visited {
text-decoration: none;
color: #FFffF;
}
html body h4 {
margin: 0;
color: #666;
}
.scene {
width: 100%;
height: 100%;
-webkit-perspective: 600;
perspective: 600;
display: -webkit-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
-webkit-box-align: center;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
}
.scene svg {
width: 240px;
height: 240px;
}
.splashscreenlogo{
position: absolute;
top: 50%;
left: 50%;
width: 100%;
/* height: 100%; */
}
#splashlogo{
position: absolute;
background-position: 50%;
/* top: 50%; */
/* width: 100%; */
/* height: 100%; */
}
.canvas_container{
position:absolute;
width:100%;
height:100%;
top:0;
left:0;
}
.white-line {
fill: none;
stroke: white;
stroke-width: 5%;
}
Any help would be awesome!
Related
Parallax effect within pinned GSAP container
I have a block which becomes pinned and scrolls horizontally. Within this block, I have a vector which has a width of 3573px. When a user scrolls horizontally, I want the vector to scroll also, alongside the images in my demo. Have tried moving my vector under .horizontalScroller__scroll, so that it scrolls alongside the images, but that didn't work. See demo: $(function() { let images = gsap.utils.toArray(".horizontalScroller__item"); gsap.to(images, { xPercent: -100 * (images.length - 1), ease: "none", scrollTrigger: { trigger: ".horizontalScroller", pin: true, scrub: 1, end: "+=3600", // size of svg bg //end: () => "+=" + document.querySelector(".horizontalScroller__images").offsetWidth } }); }); .spacer { height: 100vh; background: lightblue; } .horizontalScroller { padding: 100px 0 60px 0; background-color: #5D209F; height: 100vh; position: relative; overflow: hidden; } .horizontalScroller__intro { margin-bottom: 25px; } .horizontalScroller__scroll { height: 70%; position: relative; overflow: hidden; } .horizontalScroller__images { display: flex; align-items: center; position: relative; z-index: 1; } .horizontalScroller__item { width: 50vw; display: flex; justify-content: center; flex: 0 0 auto; } .horizontalScroller__image { -o-object-fit: fill; object-fit: fill; margin: 0 auto; width: 260px; height: 255px; } .horizontalScroller__pattern { position: absolute; top: -50%; width: 100%; height: 100%; } .horizontalScroller__pattern-inner { height: 100%; } <link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/ScrollTrigger.min.js"></script> <section class="spacer"></section> <section class="horizontalScroller"> <div class="container"> <div class="row justify-content-center"> <div class="col-12 col-md-8"> <div class="horizontalScroller__intro text-center"> <h2 class="horizontalScroller__header">Header</h2> </div> </div> </div> </div> <div class="horizontalScroller__scroll"> <div class="horizontalScroller__images" id="horizontal-scroll"> <div class="horizontalScroller__item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> <div class="horizontalScroller__item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> <div class="horizontalScroller__item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> <div class="horizontalScroller__item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> </div> </div> <div class="horizontalScroller__pattern"> <div class="horizontalScroller__pattern-inner"> <svg class="horizontalScroller__pattern-svg" xmlns="http://www.w3.org/2000/svg" width="3573.448" height="935.115" viewBox="0 0 3573.448 935.115"> <g id="Journey_line" data-name="Journey line" transform="translate(58.751 66.918)"> <path id="Path_111603" data-name="Path 111603" d="M-57.191,807.764c141.061,46.335,271.1-48.506,208.8-171.343-44.647-88.041-84.385,2.223-76.906,70.2,11.034,100.3,75.906,190.808,216.669,143.778C406.3,812,470.169,700.216,568.892,676.505c94.985-22.813,137.722,77.422,240.409,77.422,189.877,0,202.929-186.737,384.8-145.215,70.851,16.176,119.356,96.77,315.333,91.709,108.733-2.808,183.293-179.6,324.1-222.009,136.412-41.091,145.842,55.306,290.03,55.078,221.015-.348,232.464-251.918,446.846-265.314,144.5-9.029,229.247,90.469,364.966-54.532,26.116-27.9,52.772-44.257,77.079-53.559,38.931-14.9,81.644-13.148,119.848,3.795,52.233,23.165,142.179,57.218,225.578-44.538C3456.26-.7,3510.921-63.64,3510.921-63.64" fill="none" stroke="rgba(249,247,250,0.3)" stroke-miterlimit="10" stroke-width="10" /> <path class="pulse" id="Path_111604" data-name="Path 111604" d="M1922.219,474.558a33.6,33.6,0,1,1-33.6-33.6,33.6,33.6,0,0,1,33.6,33.6" fill="#5d209f" /> <path class="pulse" id="Path_111605" data-name="Path 111605" d="M1908.09,474.558a19.475,19.475,0,1,1-19.476-19.476,19.476,19.476,0,0,1,19.476,19.476" fill="#f6eb61" /> <path class="pulse" id="Path_111606" data-name="Path 111606" d="M1056.355,649.037c0-19.115-15.045-34.611-33.6-34.611s-33.6,15.5-33.6,34.611,15.045,34.611,33.6,34.611,33.6-15.5,33.6-34.611" fill="#5d209f" /> <path class="pulse" id="Path_111607" data-name="Path 111607" d="M1042.226,649.037c0-11.078-8.719-20.059-19.476-20.059s-19.475,8.981-19.475,20.059,8.719,20.059,19.475,20.059,19.476-8.981,19.476-20.059" fill="#f277c6" /> <path class="pulse" id="Path_111610" data-name="Path 111610" d="M623.423,672.044c0-18.834-15.045-34.1-33.6-34.1s-33.6,15.268-33.6,34.1,15.045,34.1,33.6,34.1,33.6-15.268,33.6-34.1" fill="#5d209f" /> <path class="pulse" id="Path_111611" data-name="Path 111611" d="M609.294,672.044a19.478,19.478,0,1,0-19.476,19.764,19.621,19.621,0,0,0,19.476-19.764" fill="#ff6d6a" /> <path class="pulse" id="Path_111608" data-name="Path 111608" d="M2355.151,439.3a33.6,33.6,0,1,0-33.6,33.6,33.6,33.6,0,0,0,33.6-33.6" fill="#5d209f" /> <path class="pulse" id="Path_111609" data-name="Path 111609" d="M2341.022,439.3a19.475,19.475,0,1,0-19.476,19.476,19.476,19.476,0,0,0,19.476-19.476" fill="#ff6d6a" /> </g> </svg> </div> </div> </section> <section class="spacer"></section>
Where you have <div class="horizontalScroller__pattern"> add horizontalScroller__SVG to it: <div class="horizontalScroller__pattern horizontalScroller__SVG"> Add the following code: let svgBG = gsap.utils.toArray(".horizontalScroller__SVG"); gsap.to(svgBG, { xPercent: -100, ease: "none", scrollTrigger: { trigger: ".horizontalScroller", pin: true, scrub: 1, end: "+=7200", //end: () => "+=" + document.querySelector(".horizontalScroller__images").offsetWidth } }); You will need to fiddle with the +7200 number until you get the desire result. $(function() { let images = gsap.utils.toArray(".horizontalScroller__item"); gsap.to(images, { xPercent: -100 * (images.length - 1), ease: "none", scrollTrigger: { trigger: ".horizontalScroller", pin: true, scrub: 1, end: "+=3600", // size of svg bg //end: () => "+=" + document.querySelector(".horizontalScroller__images").offsetWidth } }); let svgBG = gsap.utils.toArray(".horizontalScroller__svg"); gsap.to(svgBG, { xPercent: -100, ease: "none", scrollTrigger: { trigger: ".horizontalScroller", pin: true, scrub: 1, end: "+=7200", //end: () => "+=" + document.querySelector(".horizontalScroller__images").offsetWidth } }); }); .spacer { height: 100vh; background: lightblue; } .horizontalScroller { padding: 100px 0 60px 0; background-color: #5D209F; height: 100vh; position: relative; overflow: hidden; } .horizontalScroller__intro { margin-bottom: 25px; } .horizontalScroller__scroll { height: 70%; position: relative; overflow: hidden; } .horizontalScroller__image_item { width: 50vw; display: flex; justify-content: center; flex: 0 0 auto; } .horizontalScroller__images { display: flex; align-items: center; position: relative; z-index: 1; } .horizontalScroller__image { -o-object-fit: fill; object-fit: fill; margin: 0 auto; width: 260px; height: 255px; } .horizontalScroller__pattern { position: absolute; top: -50%; width: 100%; height: 100%; } .horizontalScroller__pattern-inner { height: 100%; } <link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/gsap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.9.1/ScrollTrigger.min.js"></script> <section class="spacer"></section> <section class="horizontalScroller"> <div class="container"> <div class="row justify-content-center"> <div class="col-12 col-md-8"> <div class="horizontalScroller__intro text-center"> <h2 class="horizontalScroller__header">Header</h2> </div> </div> </div> </div> <div class="horizontalScroller__scroll"> <div class="horizontalScroller__images" id="horizontal-scroll"> <div class="horizontalScroller__item horizontalScroller__image_item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> <div class="horizontalScroller__item horizontalScroller__image_item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> <div class="horizontalScroller__item horizontalScroller__image_item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> <div class="horizontalScroller__item horizontalScroller__image_item"> <div class="horizontalScroller__image" style="background-image:url('https://picsum.photos/200/300');"></div> </div> </div> </div> <div class="horizontalScroller__svg horizontalScroller__pattern"> <div class="horizontalScroller__pattern-inner"> <svg class="horizontalScroller__pattern-svg" xmlns="http://www.w3.org/2000/svg" width="3573.448" height="935.115" viewBox="0 0 3573.448 935.115"> <g id="Journey_line" data-name="Journey line" transform="translate(58.751 66.918)"> <path id="Path_111603" data-name="Path 111603" d="M-57.191,807.764c141.061,46.335,271.1-48.506,208.8-171.343-44.647-88.041-84.385,2.223-76.906,70.2,11.034,100.3,75.906,190.808,216.669,143.778C406.3,812,470.169,700.216,568.892,676.505c94.985-22.813,137.722,77.422,240.409,77.422,189.877,0,202.929-186.737,384.8-145.215,70.851,16.176,119.356,96.77,315.333,91.709,108.733-2.808,183.293-179.6,324.1-222.009,136.412-41.091,145.842,55.306,290.03,55.078,221.015-.348,232.464-251.918,446.846-265.314,144.5-9.029,229.247,90.469,364.966-54.532,26.116-27.9,52.772-44.257,77.079-53.559,38.931-14.9,81.644-13.148,119.848,3.795,52.233,23.165,142.179,57.218,225.578-44.538C3456.26-.7,3510.921-63.64,3510.921-63.64" fill="none" stroke="rgba(249,247,250,0.3)" stroke-miterlimit="10" stroke-width="10" /> <path class="pulse" id="Path_111604" data-name="Path 111604" d="M1922.219,474.558a33.6,33.6,0,1,1-33.6-33.6,33.6,33.6,0,0,1,33.6,33.6" fill="#5d209f" /> <path class="pulse" id="Path_111605" data-name="Path 111605" d="M1908.09,474.558a19.475,19.475,0,1,1-19.476-19.476,19.476,19.476,0,0,1,19.476,19.476" fill="#f6eb61" /> <path class="pulse" id="Path_111606" data-name="Path 111606" d="M1056.355,649.037c0-19.115-15.045-34.611-33.6-34.611s-33.6,15.5-33.6,34.611,15.045,34.611,33.6,34.611,33.6-15.5,33.6-34.611" fill="#5d209f" /> <path class="pulse" id="Path_111607" data-name="Path 111607" d="M1042.226,649.037c0-11.078-8.719-20.059-19.476-20.059s-19.475,8.981-19.475,20.059,8.719,20.059,19.475,20.059,19.476-8.981,19.476-20.059" fill="#f277c6" /> <path class="pulse" id="Path_111610" data-name="Path 111610" d="M623.423,672.044c0-18.834-15.045-34.1-33.6-34.1s-33.6,15.268-33.6,34.1,15.045,34.1,33.6,34.1,33.6-15.268,33.6-34.1" fill="#5d209f" /> <path class="pulse" id="Path_111611" data-name="Path 111611" d="M609.294,672.044a19.478,19.478,0,1,0-19.476,19.764,19.621,19.621,0,0,0,19.476-19.764" fill="#ff6d6a" /> <path class="pulse" id="Path_111608" data-name="Path 111608" d="M2355.151,439.3a33.6,33.6,0,1,0-33.6,33.6,33.6,33.6,0,0,0,33.6-33.6" fill="#5d209f" /> <path class="pulse" id="Path_111609" data-name="Path 111609" d="M2341.022,439.3a19.475,19.475,0,1,0-19.476,19.476,19.476,19.476,0,0,0,19.476-19.476" fill="#ff6d6a" /> </g> </svg> </div> </div> </section> <section class="spacer"></section>
Close menu when click detected outside
I'm trying to close a menu when the user clicks outside of the element. I have tried many solutions from Stack overflow but none of them work for me. The user should be able to click on the menu button (3 dots), which then shows the menu. Then if they click outside of this, it should close each time. https://jsfiddle.net/Lzeukhcj/1/ Here is my code and what I have tried: Javascript const dots = document.querySelector(".dot-wrap"); const popup = document.querySelector(".popup"); dots.onclick = () => { popup.style.display = "block"; } document.onclick = (event) => { let isClickInside = popup.contains(event.target); if (!isClickInside) { console.log("outside box"); popup.style.display = 'none'; } } SCSS .tweet-container { max-width: 100%; display: flex; padding-top: 10px; padding-bottom: 10px; padding-left: 5%; padding-right: 5%; border-bottom: solid 1px #f1f1f1; } .tweet-container-right { width: 100%; margin-left: 10px; } .tweet-header { display: flex; width: 100%; justify-content: space-between; align-items: center; z-index: 100; } .icon-container { display: flex; font-size: 0.8em; } .user-info { display: flex; align-items: center; .tweet-name { font-size: 15px; margin-right: 3px; color: #0f1419; } .tweet-username { font-size:15px; color: #526470; } .middle-dot{ margin-left: 3px; margin-right: 3px; } .time { font-size: 15px; color: #526470; } } .tweet-text { font-size: 0.8em; } .verified-tick{ margin-right: 3px; } .dots-popup-container { position: relative; .dots { width: 18px; fill: red; } .popup { background-color: white; position: absolute; right: 0; top: 0; width: 250px; display: none; /*height: 0px;*/ transition: 2s ease; box-shadow: 0 0.5px 4px 0 rgba(0, 0, 0, 0.2); padding-top: 14px; .popup-option { display: flex; margin-bottom: 20px; p { color: #526470; } .popup-icon { width: 20px; margin-left: 10px; margin-right: 10px; fill: #526470; } } } } HTML <div class="tweet-container-right"> <div class="tweet-header"> <div class="user-info"> <h3 class="tweet-name">Title </h3> <span class="middle-dot">·</span> <p class="time">2d</p> </div> <div class="dots-popup-container"> <div class="dot-wrap"> <svg viewBox="0 0 24 24" aria-hidden="true" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-1hdv0qi dots"> <g> <circle cx="5" cy="12" r="2"></circle> <circle cx="12" cy="12" r="2"></circle> <circle cx="19" cy="12" r="2"></circle> </g> </svg> </div> <div class="popup"> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M12 22.75C6.072 22.75 1.25 17.928 1.25 12S6.072 1.25 12 1.25 22.75 6.072 22.75 12 17.928 22.75 12 22.75zm0-20C6.9 2.75 2.75 6.9 2.75 12S6.9 21.25 12 21.25s9.25-4.15 9.25-9.25S17.1 2.75 12 2.75z"></path> <path d="M12 13.415c1.892 0 3.633.95 4.656 2.544.224.348.123.81-.226 1.035-.348.226-.812.124-1.036-.226-.747-1.162-2.016-1.855-3.395-1.855s-2.648.693-3.396 1.854c-.224.35-.688.45-1.036.225-.35-.224-.45-.688-.226-1.036 1.025-1.594 2.766-2.545 4.658-2.545zm4.216-3.957c0 .816-.662 1.478-1.478 1.478s-1.478-.66-1.478-1.478c0-.817.662-1.478 1.478-1.478s1.478.66 1.478 1.478zm-5.476 0c0 .816-.662 1.478-1.478 1.478s-1.478-.66-1.478-1.478c0-.817.662-1.478 1.478-1.478.817 0 1.478.66 1.478 1.478z"></path> </g> </svg></div> <p>Not interested in this tweet</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M20.083 6.173l2.323 2.323c.293.293.768.293 1.06 0s.294-.768 0-1.06l-2.32-2.326 2.322-2.323c.293-.294.293-.77 0-1.062s-.768-.293-1.06 0L20.082 4.05 17.76 1.73c-.293-.293-.768-.293-1.06 0-.147.146-.22.338-.22.53s.072.384.22.53l2.32 2.32-2.32 2.325c-.147.146-.22.338-.22.53s.072.384.22.53c.292.293.767.293 1.06 0l2.323-2.32zM8.417 11.816c1.355 0 2.872-.15 3.84-1.256.813-.93 1.077-2.367.806-4.392-.38-2.826-2.116-4.513-4.645-4.513-2.53 0-4.267 1.687-4.646 4.513-.273 2.025-.01 3.462.805 4.393.968 1.108 2.485 1.257 3.84 1.257zm-3.16-5.448c.16-1.2.786-3.212 3.16-3.212 2.373 0 2.998 2.013 3.16 3.212.207 1.55.056 2.627-.45 3.205-.455.52-1.266.743-2.71.743s-2.256-.223-2.71-.743c-.507-.578-.658-1.656-.45-3.205zm11.44 12.867c-.88-3.525-4.283-5.988-8.28-5.988-3.998 0-7.403 2.463-8.28 5.988-.172.693-.03 1.4.395 1.94.408.522 1.04.822 1.733.822H14.57c.69 0 1.323-.3 1.73-.82.425-.54.568-1.247.396-1.942zm-1.577 1.018c-.126.16-.316.245-.55.245H2.264c-.235 0-.426-.085-.552-.246-.137-.174-.18-.412-.12-.654.71-2.855 3.517-4.85 6.824-4.85s6.113 1.994 6.824 4.85c.06.24.017.48-.12.655z"></path> </g> </svg> </div> <p>Unfollow whoever</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M1.75 22.354c-.192 0-.384-.073-.53-.22-.293-.293-.293-.768 0-1.06L20.395 1.898c.293-.294.768-.294 1.06 0s.294.767 0 1.06L2.28 22.135c-.146.146-.338.22-.53.22zm1.716-5.577c-.134 0-.27-.036-.392-.11-.67-.413-1.07-1.13-1.07-1.917v-5.5c0-1.24 1.01-2.25 2.25-2.25H6.74l7.047-5.588c.225-.18.533-.215.792-.087.258.125.423.387.423.675v3.28c0 .415-.336.75-.75.75s-.75-.335-.75-.75V3.553L7.47 8.338c-.134.104-.298.162-.467.162h-2.75c-.413 0-.75.337-.75.75v5.5c0 .263.134.5.356.64.353.216.462.678.245 1.03-.14.23-.387.357-.64.357zm10.787 5.973c-.166 0-.33-.055-.466-.162l-4.795-3.803c-.325-.258-.38-.73-.122-1.054.258-.322.73-.38 1.054-.12l3.58 2.838v-7.013c0-.414.335-.75.75-.75s.75.336.75.75V22c0 .288-.166.55-.425.675-.104.05-.216.075-.327.075z"></path> </g> </svg> </div> <p>Mute whoever</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M12 1.25C6.072 1.25 1.25 6.072 1.25 12S6.072 22.75 12 22.75 22.75 17.928 22.75 12 17.928 1.25 12 1.25zm0 1.5c2.28 0 4.368.834 5.982 2.207L4.957 17.982C3.584 16.368 2.75 14.282 2.75 12c0-5.1 4.15-9.25 9.25-9.25zm0 18.5c-2.28 0-4.368-.834-5.982-2.207L19.043 6.018c1.373 1.614 2.207 3.7 2.207 5.982 0 5.1-4.15 9.25-9.25 9.25z"></path> </g> </svg> </div> <p>Block whoever</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M20.083 6.173l2.323 2.323c.293.293.768.293 1.06 0s.294-.768 0-1.06l-2.32-2.326 2.322-2.323c.293-.294.293-.77 0-1.062s-.768-.293-1.06 0L20.082 4.05 17.76 1.73c-.293-.293-.768-.293-1.06 0-.147.146-.22.338-.22.53s.072.384.22.53l2.32 2.32-2.32 2.325c-.147.146-.22.338-.22.53s.072.384.22.53c.292.293.767.293 1.06 0l2.323-2.32zM8.417 11.816c1.355 0 2.872-.15 3.84-1.256.813-.93 1.077-2.367.806-4.392-.38-2.826-2.116-4.513-4.645-4.513-2.53 0-4.267 1.687-4.646 4.513-.273 2.025-.01 3.462.805 4.393.968 1.108 2.485 1.257 3.84 1.257zm-3.16-5.448c.16-1.2.786-3.212 3.16-3.212 2.373 0 2.998 2.013 3.16 3.212.207 1.55.056 2.627-.45 3.205-.455.52-1.266.743-2.71.743s-2.256-.223-2.71-.743c-.507-.578-.658-1.656-.45-3.205zm11.44 12.867c-.88-3.525-4.283-5.988-8.28-5.988-3.998 0-7.403 2.463-8.28 5.988-.172.693-.03 1.4.395 1.94.408.522 1.04.822 1.733.822H14.57c.69 0 1.323-.3 1.73-.82.425-.54.568-1.247.396-1.942zm-1.577 1.018c-.126.16-.316.245-.55.245H2.264c-.235 0-.426-.085-.552-.246-.137-.174-.18-.412-.12-.654.71-2.855 3.517-4.85 6.824-4.85s6.113 1.994 6.824 4.85c.06.24.017.48-.12.655z"></path> </g> </svg> </div> <p>Mark as spoiler</p> </div> </div> </div> </div>
When you click the dots to open the popup, your document click event listener is checking whether the target is a child of the popup. Since the toggle is not, the modal is opened, then closed. You can fix this by using Event.stopPropagation() to prevent this click event from being captured by the document click event listener when the dots are clicked. Your JS should be: window.onload = () => { const dots = document.querySelector(".dot-wrap"); const popup = document.querySelector(".popup"); dots.onclick = (e) => { popup.style.display = "block"; e.stopPropagation(); } document.onclick = (event) => { let isClickInside = popup.contains(event.target); if (!isClickInside) { console.log("outside box"); popup.style.display = 'none'; } } } Demo: window.onload = () => { const dots = document.querySelector(".dot-wrap"); const popup = document.querySelector(".popup"); dots.onclick = (e) => { popup.style.display = "block"; e.stopPropagation(); } document.onclick = (event) => { let isClickInside = popup.contains(event.target); if (!isClickInside) { console.log("outside box"); popup.style.display = 'none'; } } } /* compiled from scss */ .tweet-container { max-width: 100%; display: flex; padding-top: 10px; padding-bottom: 10px; padding-left: 5%; padding-right: 5%; border-bottom: solid 1px #f1f1f1; } .tweet-container-right { width: 100%; margin-left: 10px; } .tweet-header { display: flex; width: 100%; justify-content: space-between; align-items: center; z-index: 100; } .icon-container { display: flex; font-size: 0.8em; } .user-info { display: flex; align-items: center; } .user-info .tweet-name { font-size: 15px; margin-right: 3px; color: #0f1419; } .user-info .tweet-username { font-size: 15px; color: #526470; } .user-info .middle-dot { margin-left: 3px; margin-right: 3px; } .user-info .time { font-size: 15px; color: #526470; } .tweet-text { font-size: 0.8em; } .verified-tick { margin-right: 3px; } .dots-popup-container { position: relative; } .dots-popup-container .dots { width: 18px; fill: red; } .dots-popup-container .popup { background-color: white; position: absolute; right: 0; top: 0; width: 250px; display: none; /*height: 0px;*/ transition: 2s ease; box-shadow: 0 0.5px 4px 0 rgba(0, 0, 0, 0.2); padding-top: 14px; } .dots-popup-container .popup .popup-option { display: flex; margin-bottom: 20px; } .dots-popup-container .popup .popup-option p { color: #526470; } .dots-popup-container .popup .popup-option .popup-icon { width: 20px; margin-left: 10px; margin-right: 10px; fill: #526470; } <div class="tweet-container"> <div class="tweet-container-right"> <div class="tweet-header"> <div class="user-info"> <h3 class="tweet-name">Title </h3> <span class="middle-dot">·</span> <p class="time">2d</p> </div> <div class="dots-popup-container"> <div class="dot-wrap"> <svg viewBox="0 0 24 24" aria-hidden="true" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-1hdv0qi dots"> <g> <circle cx="5" cy="12" r="2"></circle> <circle cx="12" cy="12" r="2"></circle> <circle cx="19" cy="12" r="2"></circle> </g> </svg> </div> <div class="popup"> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M12 22.75C6.072 22.75 1.25 17.928 1.25 12S6.072 1.25 12 1.25 22.75 6.072 22.75 12 17.928 22.75 12 22.75zm0-20C6.9 2.75 2.75 6.9 2.75 12S6.9 21.25 12 21.25s9.25-4.15 9.25-9.25S17.1 2.75 12 2.75z"></path> <path d="M12 13.415c1.892 0 3.633.95 4.656 2.544.224.348.123.81-.226 1.035-.348.226-.812.124-1.036-.226-.747-1.162-2.016-1.855-3.395-1.855s-2.648.693-3.396 1.854c-.224.35-.688.45-1.036.225-.35-.224-.45-.688-.226-1.036 1.025-1.594 2.766-2.545 4.658-2.545zm4.216-3.957c0 .816-.662 1.478-1.478 1.478s-1.478-.66-1.478-1.478c0-.817.662-1.478 1.478-1.478s1.478.66 1.478 1.478zm-5.476 0c0 .816-.662 1.478-1.478 1.478s-1.478-.66-1.478-1.478c0-.817.662-1.478 1.478-1.478.817 0 1.478.66 1.478 1.478z"></path> </g> </svg></div> <p>Not interested in this tweet</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M20.083 6.173l2.323 2.323c.293.293.768.293 1.06 0s.294-.768 0-1.06l-2.32-2.326 2.322-2.323c.293-.294.293-.77 0-1.062s-.768-.293-1.06 0L20.082 4.05 17.76 1.73c-.293-.293-.768-.293-1.06 0-.147.146-.22.338-.22.53s.072.384.22.53l2.32 2.32-2.32 2.325c-.147.146-.22.338-.22.53s.072.384.22.53c.292.293.767.293 1.06 0l2.323-2.32zM8.417 11.816c1.355 0 2.872-.15 3.84-1.256.813-.93 1.077-2.367.806-4.392-.38-2.826-2.116-4.513-4.645-4.513-2.53 0-4.267 1.687-4.646 4.513-.273 2.025-.01 3.462.805 4.393.968 1.108 2.485 1.257 3.84 1.257zm-3.16-5.448c.16-1.2.786-3.212 3.16-3.212 2.373 0 2.998 2.013 3.16 3.212.207 1.55.056 2.627-.45 3.205-.455.52-1.266.743-2.71.743s-2.256-.223-2.71-.743c-.507-.578-.658-1.656-.45-3.205zm11.44 12.867c-.88-3.525-4.283-5.988-8.28-5.988-3.998 0-7.403 2.463-8.28 5.988-.172.693-.03 1.4.395 1.94.408.522 1.04.822 1.733.822H14.57c.69 0 1.323-.3 1.73-.82.425-.54.568-1.247.396-1.942zm-1.577 1.018c-.126.16-.316.245-.55.245H2.264c-.235 0-.426-.085-.552-.246-.137-.174-.18-.412-.12-.654.71-2.855 3.517-4.85 6.824-4.85s6.113 1.994 6.824 4.85c.06.24.017.48-.12.655z"></path> </g> </svg> </div> <p>Unfollow whoever</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M1.75 22.354c-.192 0-.384-.073-.53-.22-.293-.293-.293-.768 0-1.06L20.395 1.898c.293-.294.768-.294 1.06 0s.294.767 0 1.06L2.28 22.135c-.146.146-.338.22-.53.22zm1.716-5.577c-.134 0-.27-.036-.392-.11-.67-.413-1.07-1.13-1.07-1.917v-5.5c0-1.24 1.01-2.25 2.25-2.25H6.74l7.047-5.588c.225-.18.533-.215.792-.087.258.125.423.387.423.675v3.28c0 .415-.336.75-.75.75s-.75-.335-.75-.75V3.553L7.47 8.338c-.134.104-.298.162-.467.162h-2.75c-.413 0-.75.337-.75.75v5.5c0 .263.134.5.356.64.353.216.462.678.245 1.03-.14.23-.387.357-.64.357zm10.787 5.973c-.166 0-.33-.055-.466-.162l-4.795-3.803c-.325-.258-.38-.73-.122-1.054.258-.322.73-.38 1.054-.12l3.58 2.838v-7.013c0-.414.335-.75.75-.75s.75.336.75.75V22c0 .288-.166.55-.425.675-.104.05-.216.075-.327.075z"></path> </g> </svg> </div> <p>Mute whoever</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M12 1.25C6.072 1.25 1.25 6.072 1.25 12S6.072 22.75 12 22.75 22.75 17.928 22.75 12 17.928 1.25 12 1.25zm0 1.5c2.28 0 4.368.834 5.982 2.207L4.957 17.982C3.584 16.368 2.75 14.282 2.75 12c0-5.1 4.15-9.25 9.25-9.25zm0 18.5c-2.28 0-4.368-.834-5.982-2.207L19.043 6.018c1.373 1.614 2.207 3.7 2.207 5.982 0 5.1-4.15 9.25-9.25 9.25z"></path> </g> </svg> </div> <p>Block whoever</p> </div> <div class="popup-option"> <div> <svg viewBox="0 0 24 24" aria-hidden="true" class="popup-icon"> <g> <path d="M20.083 6.173l2.323 2.323c.293.293.768.293 1.06 0s.294-.768 0-1.06l-2.32-2.326 2.322-2.323c.293-.294.293-.77 0-1.062s-.768-.293-1.06 0L20.082 4.05 17.76 1.73c-.293-.293-.768-.293-1.06 0-.147.146-.22.338-.22.53s.072.384.22.53l2.32 2.32-2.32 2.325c-.147.146-.22.338-.22.53s.072.384.22.53c.292.293.767.293 1.06 0l2.323-2.32zM8.417 11.816c1.355 0 2.872-.15 3.84-1.256.813-.93 1.077-2.367.806-4.392-.38-2.826-2.116-4.513-4.645-4.513-2.53 0-4.267 1.687-4.646 4.513-.273 2.025-.01 3.462.805 4.393.968 1.108 2.485 1.257 3.84 1.257zm-3.16-5.448c.16-1.2.786-3.212 3.16-3.212 2.373 0 2.998 2.013 3.16 3.212.207 1.55.056 2.627-.45 3.205-.455.52-1.266.743-2.71.743s-2.256-.223-2.71-.743c-.507-.578-.658-1.656-.45-3.205zm11.44 12.867c-.88-3.525-4.283-5.988-8.28-5.988-3.998 0-7.403 2.463-8.28 5.988-.172.693-.03 1.4.395 1.94.408.522 1.04.822 1.733.822H14.57c.69 0 1.323-.3 1.73-.82.425-.54.568-1.247.396-1.942zm-1.577 1.018c-.126.16-.316.245-.55.245H2.264c-.235 0-.426-.085-.552-.246-.137-.174-.18-.412-.12-.654.71-2.855 3.517-4.85 6.824-4.85s6.113 1.994 6.824 4.85c.06.24.017.48-.12.655z"></path> </g> </svg> </div> <p>Mark as spoiler</p> </div> </div> </div> </div>
Create a dotted path that follows a curve
I have a design I'm trying to port over to code, the design is as follows: I've created the majority of the design in code already (just a prototype so the html/css isn't perfect), but the area I'm struggling with is the dotted progression that you can see within the curved path .frame { width: 375px; height: 750px; background: #171B42; background: linear-gradient(to bottom, #171B42, #171B42 50%, #3C98FF 110%); position: relative; } #earth { position: absolute; bottom: 0; left: 0; right: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%) } .locked { text-align: center; margin: 76px auto; width: 230px; position: relative; } .locked img { width: 60px; margin: 0 26px; } .locked.row-1:after { content: ""; width: 163px; height: 175px; background: url(https://i.imgur.com/u6v9Dkd.png) center center no-repeat; background-size: cover; position: absolute; top: -130px; right: -50px; bottom: 0; z-index: -1; } .locked.row-2:after { content: ""; width: 163px; height: 175px; background: url(https://i.imgur.com/u6v9Dkd.png) center center no-repeat; background-size: cover; position: absolute; top: -127px; left: -46px; bottom: 0; z-index: -1; transform: rotate(180deg); } .path-map { position: absolute; bottom: 180px; left: 0; right: 0; left: 50%; -webkit-transform: translateX(-50%); transform: translateX(-50%); width:375px; } <div class="frame"> <div class="path-map"> <div class="locked row-2"> <img src="https://i.imgur.com/h3ElY2f_d.webp?maxwidth=728&fidelity=grand"> <img src="https://i.imgur.com/h3ElY2f_d.webp?maxwidth=728&fidelity=grand"> </div> <div class="locked row-1"> <img src="https://i.imgur.com/h3ElY2f_d.webp?maxwidth=728&fidelity=grand"> </div> </div> <img id="earth" src="https://i.imgur.com/RR8kQx1_d.webp?maxwidth=728&fidelity=grand"/> </div> I'm wondering if anyone has any ideas on how to create that dotted path, it might require some javascript? I'm not entirely sure what the best way of solving this would be outside of just manually adding each dot with position: absolute. Any help would be amazing, thank you!
Here's an example of how this can be done using SVG <path> elements, <use> elements, a <mask> element, the stroke-dasharray attribute, and the stroke-linecap attribute. You can define a single <path> element once, and then reuse it multiple times with different stroke styles or masks applied to it, which is especially handy in this case. body { background: darkblue; } <svg viewBox="0 0 515 515"> <defs> <mask id="mask"> <rect fill="black" x="0" y="0" width="515" height="515"></rect> <rect fill="white" x="0" y="200" width="515" height="315"></rect> </mask> <path id="path" fill="none" d="M138 414C192.333 414 312.8 414 360 414C419 414 504 262 360 262C216 262 261 262 153 262C45 262 39 130 144 130C249 130 327 130 378 130C429 130 452 83 452 -2C452 -87 472 -87 452 -87"></path> </defs> <!-- solid wide line --> <use href="#path" stroke="rgba(255,255,255,0.2)" stroke-width="20"></use> <!-- solid narrow line --> <use href="#path" stroke="rgba(255,255,255,0.2)" stroke-width="10"></use> <!-- dotted full line --> <use href="#path" stroke="rgba(255,255,255,0.2)" stroke-width="5" stroke-dasharray="0 10" stroke-linecap="round"></use> <!-- dotted masked line --> <use href="#path" stroke="rgba(255,255,255,0.8)" stroke-width="5" stroke-dasharray="0 10" stroke-linecap="round" mask="url(#mask)"></use> </svg>
Hide vertical scrollbar
I’d like to hide the vertical scroll-bars in the left panels, while keeping them scrollable. Edit: Webkit covered. Now looking for a fix for Mozilla Firefox I’ve looked at answers from previous questions, such as this one and that one, with poor results. Mostly they mess up the layout, causing overlaps, or they don’t produce any noticeable result. Browsers evolve rapidly so I was hoping for updated information. A cross-browser solution would be awesome, but I’d be happy with any pointers! jsfiddle const lijntjes = [ "Random sentences go here, one at a time!", "Here's another one! Just keep adding them on.", "Look, here's another one.", "And yet another. Along with dozens of others." ]; const lorIps = el => { for (let n = 0; n < 15; n++) { el.innerHTML += ' ' + lijntjes.join(' ').toString() }; }; const teksten = document.querySelectorAll('.tekst'); const po1 = document.querySelectorAll('.project-omschrijving.row-1'); const po2 = document.querySelectorAll('.project-omschrijving.row-2'); const om = document.querySelectorAll('.omschrijving'); const o = document.querySelectorAll('.open'); const c = document.querySelectorAll('.close'); // Populate Array.from(teksten, item => lorIps(item)); // Toggler const toggler = (el, klassen) => klassen.map(klas => el.classList.toggle(klas)); // Open const open = elmt => { Array.from(elmt, item => item.addEventListener('click', function() { let hoofdNodes = document.querySelectorAll('.' + this.parentNode.parentNode.classList.value.split(' ').join( '.').replace('.omschrijving', '')) Array.from(hoofdNodes, el => toggler(el, ['trans', 'binnen'])); })); } // Close const dicht = elmt => { Array.from(elmt, item => item.addEventListener('click', function() { let hoofdNodes = document.querySelectorAll('.' + this.parentNode.parentNode.classList.value.split( ' ').join( '.').replace('.omschrijving', '')); Array.from(hoofdNodes, el => setTimeout(() => toggler(el, ['trans']), 200)); Array.from(hoofdNodes, el => toggler(el, ['binnen'])) })) } window.onload = function() { open(o); dicht(c); o[0].click() } :root { --offset: 50vw; --cell-hoogte: 50vh; --gap: '1em'; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; font-size: 12px; } a { text-decoration: none; color: palegreen; } :target { border-radius: 1em; background-color: palegreen; transition: background-color .3s ease-in-out } :target> :nth-child(2) { color: #fff; transition: color .3s ease-in-out } .container { color: green; font-size: 2em; font-weight: bold; display: grid; grid-template-columns: var(--offset) 100vw; grid-template-rows: repeat(2, var(--cell-hoogte)); grid-gap: var(--gap); overflow: hidden; } #media (max-width: 700px) { .container { grid-template-columns: 50vw 100vw; grid-template-rows: repeat(2, calc(var(--cell-hoogte)*1)); grid-gap: 0; } } p { /* Viewport Sized Typography */ /* https://css-tricks.com/viewport-sized-typography/ */ font-size: 3.5vmin; } p a { display: block; transition: background .3s ease-in-out } #note { position: fixed; bottom: 1em; right: 1em; display: flex; align-self: flex-end; } .omschrijving { opacity: .5; } .trans { transition: all .2s ease-out; } .project-omschrijving { will-change: transform, opacity; padding: 1em; transform: translateX(calc(var(--offset)*-1)); overflow: hidden; } .project-omschrijving:nth-child(odd) { overflow-y: auto; } .binnen { transform: translateX(0); transition: all .3s ease-out; opacity: 1 } .knop { display: flex; flex-direction: column; } .open, .close { position: absolute; top: 1em; right: 0; width: 4em; height: auto; cursor: pointer; stroke: green; fill: green; stroke-miterlimit: 10; object-fit: contain; } .close { transform: rotate(45deg) } <div class="container"> <p id="anchor1" class="project-omschrijving omschrijving row-1"> <span class='anchor'>Anchor 1</span> To anchor3 <span class="knop"> <a class="close"> <svg class="checkmark" viewBox="-5 -5 115 115" xmlns="http://www.w3.org/2000/svg"> <line x1="0" x2="50" y1="25" y2="25" stroke-width="5px" stroke-linecap="square" /> <line x1="0" x2="50" y1="25" y2="25" stroke-width="5px" stroke-linecap="square" transform="translate(50) rotate(90)" /> </svg> </a> </span> <span class="tekst"></span> </p> <p id="anchor2" class="project-omschrijving row-1"> <span class='anchor'>Anchor 2</span> To anchor4 <span class="knop"> <a class="open"> <svg class="checkmark" viewBox="-5 -5 115 115" xmlns="http://www.w3.org/2000/svg"> <circle cx="25" cy="25" r="25" /> </svg> </a> </span> <span class="tekst"></span> </p> <p id="anchor3" class="project-omschrijving omschrijving row-2"> <span class='anchor'>Anchor 3</span> To anchor1 <span class="knop"> <a class="close"> <svg class="checkmark" viewBox="-5 -5 115 115" xmlns="http://www.w3.org/2000/svg"> <line x1="0" x2="50" y1="25" y2="25" stroke-width="5px" stroke-linecap="square" /> <line x1="0" x2="50" y1="25" y2="25" stroke-width="5px" stroke-linecap="square" transform="translate(50) rotate(90)" /> </svg> </a> </span> <span class="tekst"></span> </p> <p id="anchor4" class="project-omschrijving row-2"> <span class='anchor'>Anchor 4</span> To anchor2 <span class="knop"> <a class="open"> <svg class="checkmark" viewBox="-5 -5 115 115" xmlns="http://www.w3.org/2000/svg"> <circle cx="25" cy="25" r="25" /> </svg> </a> </span> <span class="tekst"></span> </p> </div> <div id="note"> Internet Explorer 8 and earlier versions do not support the :target selector.</div>
I want my elements to fadein and fade out and then the page to close and load another page
Not sure if its possible however what I would like to achieve is the following: My element with the class ".splashscreenlogo" to show when the document is ready, I would like it to show for 2.5 seconds before it fades out and then my element with a class ".scene" fades in for a further 3 seconds before it fades out again. Once this has finished the whole page redirects to another html page. Current html: <div class="scene"> <svg version="1.1" id="dc-spinner" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width:"38" height:"38" viewBox="0 0 38 38" preserveAspectRatio="xMinYMin meet" > <text x="14" y="21" font-family="Monaco" font-size="2px" style="letter-spacing:0.6" fill="grey">LOADING <animate attributeName="opacity" values="0;1;0" dur="1.8s" repeatCount="indefinite"/> </text> <path fill="#2AA198" stroke="#ffffff" stroke-width="0.5027" stroke-miterlimit="10" d="M5.203,20 c0-8.159,6.638-14.797,14.797-14.797V5C11.729,5,5,11.729,5,20s6.729,15,15,15v-0.203C11.841,34.797,5.203,28.159,5.203,20z"> <animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" calcMode="spline" keySplines="0.4, 0, 0.2, 1" keyTimes="0;1" dur="2s" repeatCount="indefinite" /> </path> <path fill="#859900" stroke="#ffffff" stroke-width="0.5027" stroke-miterlimit="10" d="M7.078,20 c0-7.125,5.797-12.922,12.922-12.922V6.875C12.763,6.875,6.875,12.763,6.875,20S12.763,33.125,20,33.125v-0.203 C12.875,32.922,7.078,27.125,7.078,20z"> <animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="1.8s" repeatCount="indefinite" /> </path> </svg> </div> <div class="splashscreenlogo"> <img src="logo_splashscreen.png" alt="Splashscreen logo" style="width:100%;height:auto"> </div> My CSS: html { height: 100%; min-height: 100%; overflow: hidden; } html body { background: url("Splashscreen.png") no-repeat; background-size: 100%; font: 14px/21px Monaco, sans-serif; color: none; font-smoothing: antialiased; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; min-height: 100%; } html body a, html body a:visited { text-decoration: none; color: #FFffF; } html body h4 { margin: 0; color: #666; } .scene { width: 100%; height: 100%; -webkit-perspective: 600; perspective: 600; display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-box-align: center; -webkit-align-items: center; -ms-flex-align: center; align-items: center; -webkit-box-pack: center; -webkit-justify-content: center; -ms-flex-pack: center; justify-content: center; } .scene svg { width: 240px; height: 240px; } .splashscreenlogo{ position: absolute; top: 46%; left: 36%; } Any help would be much appreciated!
assuming you have JQuery since you mentioned in tags, use this to achieve what you want. $(document).ready(function() { //hiding initially $('.scene').hide(); //Fade In and delay 2.5 sec then Fade Out $('.splashscreenlogo').hide().fadeIn(function() { $(this).delay(2500).fadeOut(function() { //Fade In and delay 3 sec then Fade Out $('.scene').fadeIn(function() { $(this).delay(3000).fadeOut(function() { //Redirect to any location alert('redirecting to page'); window.location = 'http://google.com'; }); }); }); }); });
You can also try to use SVG's onend event and the repeatCount to form a counter to call a redirecting function like the following: <svg version="1.1" id="dc-spinner" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" width:"38" height:"38" viewBox="0 0 38 38" preserveAspectRatio="xMinYMin meet"> <script src="text/javascript"> <![CDATA[ function redirect() { alert("Redirecting."); } ]]> </script> <text x="14" y="21" font-family="Monaco" font-size="2px" style="letter-spacing:0.6" fill="grey"> LOADING <animate attributeName="opacity" values="0;1;0" dur="1.8s" repeatCount="2" onend="redirect()"/> </text> <path fill="#2AA198" stroke="#ffffff" stroke-width="0.5027" stroke-miterlimit="10" d="M5.203,20c0-8.159,6.638-14.797,14.797-14.797V5C11.729,5,5,11.729,5,20s6.729,15,15,15v-0.203C11.841,34.797,5.203,28.159,5.203,20z"> <animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" calcMode="spline" keySplines="0.4, 0, 0.2, 1" keyTimes="0;1" dur="2s" repeatCount="indefinite" /> </path> <path fill="#859900" stroke="#ffffff" stroke-width="0.5027" stroke-miterlimit="10" d="M7.078,20c0-7.125,5.797-12.922,12.922-12.922V6.875C12.763,6.875,6.875,12.763,6.875,20S12.763,33.125,20,33.125v-0.203C12.875,32.922,7.078,27.125,7.078,20z"> <animateTransform attributeName="transform" type="rotate" from="0 20 20" to="360 20 20" dur="1.8s" repeatCount="indefinite" /> </path> </svg> DEMO Here You can also try modifying the dur and the repeatCount attributes in the animate tag to match your requirement.
You can use javascript to go to an other page when the animations are ready. $(document).ready(function(){ setTimeout(function(){ window.location = 'https://www.google.com/'; },3000); }) /* for the time I have choosen a random time. note that the time is in miliseconds one sec has 1000 ms. */ I used Jquery for this because Idon't know how to detect a page ready but you can search that and apply it tou your code. For the time you have to count the total time of the animation and replace the 500 miliseconds by your time