I Made a code to make a website that asks you to choose the language and go to the site, but the opacity animation with transition…
var Lang;
setTimeout(function() {
document.getElementById("SelectLanguage-text").style.filter = "opacity(100%)";
document.getElementById("SelectLanguage-text").style.top = "0";
document.getElementsByClassName("EN")[0].style.display = "block";
document.getElementsByClassName("AR")[0].style.display = "block";
}, 1000);
setTimeout(function() {
document.getElementById("SelectLanguage-text-ar").style.filter = "opacity(100%)";
document.getElementById("SelectLanguage-text-ar").style.top = "0";
document.getElementsByClassName("EN")[0].style.filter = "opacity(100%)";
document.getElementsByClassName("EN")[0].style.top = "0";
}, 1100);
setTimeout(function() {
document.getElementsByClassName("AR")[0].style.filter = "opacity(100%)";
document.getElementsByClassName("AR")[0].style.top = "0";
}, 1200);
document.getElementsByClassName("AR")[0].onclick = function() {
Lang = "AR";
Start();
}
document.getElementsByClassName("EN")[0].onclick = function() {
Lang = "EN";
Start();
}
document.getElementById("Switch").onclick = function() {
if (Lang == "AR") {
Lang = "EN";
Start();
} else {
Lang = "AR";
Start();
}
}
document.getElementById("Return").onclick = function() {
location.reload();
}
function Start() {
document.getElementById("select-language").style.filter = "opacity(0%)";
setTimeout(function() {
document.getElementById("select-language").style.display = "none";
document.getElementById("AllOtherSects").style.display = "block";
document.getElementById("AllOtherSects").style.filter = "opacity(100%)";
document.getElementById("AllOtherSects").style.top = "0";
document.getElementsByTagName("nav")[0].style.display = "flex";
document.getElementsByTagName("nav")[0].style.filter = "opacity(100%)";
}, 500)
if (Lang == "AR") {
document.getElementsByTagName("nav")[0].style.direction = "rtl";
document.getElementsByTagName("nav")[0].style.textAlign = "right";
document.getElementsByTagName("h1")[0].innerHTML = "تعلم البرمجة";
document.getElementsByTagName("h1")[0].style.fontFamily = "Arabic";
document.getElementsByTagName("a")[0].innerHTML = "الرئيسية";
document.getElementsByTagName("a")[1].innerHTML = "عن";
document.getElementsByTagName("a")[2].innerHTML = "اتصل بنا";
document.getElementsByTagName("h1")[3].innerHTML = "تعلم البرمجة";
document.getElementById("OR").innerHTML = "أو";
document.getElementById("Switch").innerHTML = "تبديل اللغة";
document.getElementById("Return").innerHTML = "العودة للتحديد";
} else {
document.getElementsByTagName("nav")[0].style.direction = "ltr";
document.getElementsByTagName("nav")[0].style.textAlign = "left";
document.getElementsByTagName("h1")[0].innerHTML = "Learn Code";
document.getElementsByTagName("h1")[0].style.fontFamily = "Title";
document.getElementsByTagName("a")[0].innerHTML = "Home";
document.getElementsByTagName("a")[1].innerHTML = "About";
document.getElementsByTagName("a")[2].innerHTML = "Contact";
document.getElementsByTagName("h1")[3].innerHTML = "Learn Code";
document.getElementById("OR").innerHTML = "OR";
document.getElementById("Switch").innerHTML = "Switch Language";
document.getElementById("Return").innerHTML = "Return To Setup";
}
}
@font-face {
font-family: Title;
src: url(Fonts/cream_beige/Cream Beige.ttf);
}
@font-face {
font-family: Arabic;
src: url(Fonts/Rubik/static/Rubik-Regular.ttf);
}
.Flex {
display: flex;
}
/* to make every div with this class flex*/
* {
transition: 0.5s;
font-family: Rubik;
}
body {
background-image: linear-gradient(rgba(0, 0, 0, 0.57), rgba(0, 0, 0, 0.57)), url("https://i.ytimg.com/vi/PIhVTAdmouw/maxresdefault.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
animation: BackgroundAnimation 20s infinite ease-in-out;
color: white;
margin: 0;
padding: 0;
}
@keyframes BackgroundAnimation {
0% {
background-position: left;
}
50% {
background-position: right;
}
100% {
background-position: left;
}
}
section {
height: 100vh;
}
nav {
padding: 20px;
display: none;
filter: opacity(0);
align-items: center;
position: fixed;
width: 100%;
}
nav h1 {
margin: 10px;
font-size: xx-large;
font-family: Title;
font-weight: 100;
}
nav a {
margin: 0 20px;
font-size: 20px;
}
a {
text-decoration: none;
color: white;
}
#select-language {
height: 97vh;
width: 100%;
text-align: center;
align-content: center;
}
#SelectLanguage-text {
margin-bottom: 0;
position: relative;
top: 30px;
filter: opacity(0);
}
#SelectLanguage-text-ar {
letter-spacing: 2px;
margin-top: 0;
position: relative;
top: 30px;
filter: opacity(0);
font-family: Arabic;
}
#select-language button {
background-color: rgba(0, 0, 0, 0.61);
color: white;
border: 10px white solid;
padding: 20px 70px;
font-size: large;
margin: 20px;
}
#select-language button:hover {
/*padding: 30px 100px;*/
transform: scale(1.2);
}
.AR,
.EN {
top: 30px;
display: none;
position: relative;
filter: opacity(0);
}
#AllOtherSects {
display: none;
position: relative;
filter: opacity(0);
top: 30px
}
#S1 {
color: white;
text-align: center;
align-content: center;
}
#S1 h1 {
font-size: 100px;
}
.transparent {
background-color: transparent;
border: none;
color: white;
font-size: large;
margin: 20px;
}
.transparent:hover {
/*padding: 30px 100px;*/
transform: scale(1.2);
}
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
</head>
<body>
<nav>
<img src="Images/code-slash.svg" alt="">
<h1>Learn Code</h1>
<a href="Home.html">Home</a>
<a href="About.html">About</a>
<a href="Contact.html">Contact</a>
</nav>
<section id="select-language">
<h1 style="font-size: 40px; font-weight: 300;" id="SelectLanguage-text">Select Language</h1>
<h1 style="font-size: 40px; font-weight: 300;" id="SelectLanguage-text-ar">اختر اللغة</h1>
<div class="Flex" style="justify-content: center; flex-wrap: wrap;">
<button class="AR" onclick="">العربية</button>
<button class="EN" onclick="">English</button>
</div>
</section>
<div id="AllOtherSects">
<section id="S1">
<h1>The Coding</h1>
<button id="Switch" class="transparent">Switch Language</button><label id="OR"> OR </label><button id="Return" class="transparent">Return To Setup</button>
</section>
</div>
<script src="Script.js"></script>
</body>
</html>
You Will Notice That the body when you click on English Or العربية Appears Instantly Without An Opacity Animation. But It Works Only at the start.
I Tried To Replace The Opacity With Scale, So The code looks like this:
@font-face {
font-family: Title;
src: url(Fonts/cream_beige/Cream Beige.ttf);
}
@font-face {
font-family: Arabic;
src: url(Fonts/Rubik/static/Rubik-Regular.ttf);
}
.Flex {
display: flex;
}
/* to make every div with this class flex*/
* {
transition: 0.5s;
font-family: Arabic;
}
body {
background-image: linear-gradient(rgba(0, 0, 0, 0.57),rgba(0, 0, 0, 0.57)),url(Images/Background.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
animation: BackgroundAnimation 20s infinite ease-in-out;
color: white;
margin: 0;
padding: 0;
}
@keyframes BackgroundAnimation {
0% {
background-position: left;
}
50% {
background-position: right;
}
100% {
background-position: left;
}
}
section {
height: 100vh;
}
nav {
padding: 20px;
display: none;
filter: opacity(0);
align-items: center;
position: fixed;
width: 100%;
}
nav h1 {
margin: 10px;
font-size: xx-large;
font-family: Title;
font-weight: 100;
}
nav a {
margin: 0 20px;
font-size: 20px;
}
a {
text-decoration: none;
color: white;
}
#select-language {
height: 97vh;
width: 100%;
text-align: center;
align-content: center;
}
#SelectLanguage-text {
margin-bottom: 0;
position: relative;
top: 30px;
filter: opacity(0);
}
#SelectLanguage-text-ar {
letter-spacing: 2px;
margin-top: 0;
position: relative;
top: 30px;
filter: opacity(0);
font-family: Arabic;
}
#select-language button {
background-color: rgba(0, 0, 0, 0.61);
color: white;
border: 10px white solid;
padding: 20px 70px;
font-size: large;
margin: 20px;
}
#select-language button:hover {
/*padding: 30px 100px;*/
transform: scale(1.2);
}
.AR,.EN {
top: 30px;
display: none;
position: relative;
filter: opacity(0);
}
#AllOtherSects {
display: none;
position: relative;
filter: opacity(0);
top: 30px
}
#S1 {
color: white;
text-align: center;
align-content: center;
}
#S1 h1 {
font-size: 100px;
}
.transparent {
background-color: transparent;
border: none;
color: white;
font-size: large;
margin: 20px;
}
.transparent:hover {
/*padding: 30px 100px;*/
transform: scale(1.2);
}
document.getElementById("select-language").style.transform = "scale(1)";
setTimeout(function(){
document.getElementById("select-language").style.display = "none";
document.getElementById("AllOtherSects").style.display = "block";
document.getElementById("AllOtherSects").style.transform = "scale(1)";
document.getElementById("AllOtherSects").style.top = "0";
document.getElementsByTagName("nav")[0].style.display = "flex";
document.getElementsByTagName("nav")[0].style.transform = "scale(1)";
},500)
But It Also Didn’t Work!