When you click 'Resume' some text comes in from the left. This is because I gave negative margin to the text initially.
But negative margin of intro_page
gives no effect.
What I want is that:
When I click resume_page
, text of resume should come in from left (this works) and text of intro_page
should go out to the right (this doesn't work).
Negative margin of intro_page
doesn't seem to be working. Why is that?
Initially, page should be empty except the two links. Currently, intro_page
page is shown. resume_page
is hidden properly, as desired.
In short, everything about resume_page
works perfectly. I want the exact same things to happen to intro_page
function clicked_resume(OnScreen)
{
var resume = document.getElementById('resume_page');
if(OnScreen == 1)
{
resume.className = '';
clicked_about(0);
}
else if(OnScreen == 0)
{
resume.className = 'unseen';
}
}
function clicked_about(OnScreen)
{
var about = document.getElementById('intro_page');
if(OnScreen == 1)
{
about.className = '';
clicked_resume(0);
}
else if(OnScreen == 0)
{
about.className = 'unseen';
}
}
#intro_page.unseen{
display: block;
margin-right: -200px;
}
#intro_page{
margin-right: 0px;
display: block;
-webkit-transition: margin-right 1.5s ease-in;
transition: margin-right 1.5s ease-in;
}
#resume_page.unseen{
display: block;
margin-left: -600px;
}
#resume_page{
margin-left: 0px;
display: block;
-webkit-transition: margin-left 1.0s ease-in;
transition: margin-left 1.0s ease-in;
}
<h2 class="title_bar">
<ul>
<li><span onclick = "clicked_about(1)">About</span></li>
<li><span onclick="clicked_resume(1)">Resume</span></li>
</ul>
</h2>
<div id="intro_page" class="unseen">
<p id="intro_main_text"> I enjoy reading, swimming, jogging, painting and exploring. </p>
<figure class="intro_pic1">
<img src="img/award.jpg" alt="Receiving Award" height="50" />
<figcaption>Award 2015</figcaption>
</figure>
</div>
<div id="resume_page" class="unseen">
<p>My resume</p>
</div>
Try using position: relative
and right
instead of margin-right
. It's more reliable since it doesn't take the element's position into account when positioning other elements, like margin
does. For bonus points you could even use transform: translate
instead of right
.
function clicked_resume(OnScreen)
{
var resume = document.getElementById('resume_page');
if(OnScreen == 1)
{
resume.className = '';
clicked_about(0);
}
else if(OnScreen == 0)
{
resume.className = 'unseen';
}
}
function clicked_about(OnScreen)
{
var about = document.getElementById('intro_page');
if(OnScreen == 1)
{
about.className = '';
clicked_resume(0);
}
else if(OnScreen == 0)
{
about.className = 'unseen';
}
}
body {
margin: 0;
overflow-x: hidden;
}
#intro_page.unseen{
display: block;
right: -100%;
}
#intro_page{
position: relative;
right: 0px;
display: block;
-webkit-transition: right 1.5s ease-in;
transition: right 1.5s ease-in;
}
#resume_page.unseen{
display: block;
left: -600px;
}
#resume_page{
position: relative;
left: 0px;
display: block;
-webkit-transition: left 1.0s ease-in;
transition: left 1.0s ease-in;
}
<h2 class="title_bar">
<ul>
<li><span onclick = "clicked_about(1)">About</span></li>
<li><span onclick="clicked_resume(1)">Resume</span></li>
</ul>
</h2>
<div id="intro_page" class="unseen">
<p id="intro_main_text"> I enjoy reading, swimming, jogging, painting and exploring. </p>
<figure class="intro_pic1">
<img src="img/award.jpg" alt="Receiving Award" height="50" />
<figcaption>Award 2015</figcaption>
</figure>
</div>
<div id="resume_page" class="unseen">
<p>My resume</p>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With