Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0
GregLassale

Would this code work? (Sofia template)

Question

Posted (edited)

Site URL: http://gregorylassale.com

Hi,

 

I've been trying forever to figure out how to add animated / clickable scroll down arrows on my site. I found this page

https://codepen.io/nxworld/pen/OyRrGy

 

I like the arrow in section 5. Through trial and error, I managed to remove the code that didn't seem necessary for me and I tweaked the ID and class tag a bit.  Would it work on my site? If so, do I put the HTML in a code block? Does the CSS go in Custom CSS and the javascript in the Code Injection header? 

The HTML

<section id="arrow" class="scroll">
  <a href="#services"><span></span>Scroll</a>
</section>

 

The CSS

.scroll a {
  position: absolute;
  bottom: 20px;
  left: 50%;
  z-index: 2;
  display: inline-block;
  -webkit-transform: translate(0, -50%);
  transform: translate(0, -50%);
  color: black;
  font : normal 400 20px/1 'montserrat', sans-serif;
  letter-spacing: .1em;
  text-decoration: none;
  transition: opacity .3s;
}
.scroll a:hover {
  opacity: .5;
}

#arrow a {
  padding-top: 70px;
}
#arrow a span {
  position: absolute;
  top: 0;
  left: 50%;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  border-left: 1px solid black;
  border-bottom: 1px solid black;
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
  -webkit-animation: sdb05 1.5s infinite;
  animation: sdb05 1.5s infinite;
  box-sizing: border-box;
}
@-webkit-keyframes sdb05 {
  0% {
    -webkit-transform: rotate(-45deg) translate(0, 0);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    -webkit-transform: rotate(-45deg) translate(-20px, 20px);
    opacity: 0;
  }
}
@keyframes sdb05 {
  0% {
    transform: rotate(-45deg) translate(0, 0);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: rotate(-45deg) translate(-20px, 20px);
    opacity: 0;
  }
}

 

The JS:

<script>
  $(function() {
  $('a[href*=#]').on('click', function(e) {
    e.preventDefault();
    $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 500, 'linear');
  });
});
</script>

 

Thanks in advance for any help. 

Edited by GregLassale

Share this post


Link to post

5 answers to this question

Recommended Posts

  • 0

Add all to Code Block (with CSS, wrap in style tag <style>paste css here</style>)

11 hours ago, carolinacantante said:

how did you do it?

 

 


You can send your question to my email to get faster answer. / How to Setup Password & Share URL 

-- I'm Tuan. I work for a non-profit project (promote the establishment of free libraries). I check the forum once or twice a day to help out the community. If you don't see me answering your question, you can send it to the email above. There are so many questions every day so I can't answer them all at once, I will try to answer them in the next few days.

Share this post


Link to post
  • 0
On 4/18/2020 at 3:02 AM, tuanphan said:

Add all to Code Block (with CSS, wrap in style tag <style>paste css here</style>)

 

but what should be inside de paste css here

 

i need to add an arrow to scroll down

Share this post


Link to post
  • 0
20 hours ago, carolinacantante said:

but what should be inside de paste css here

 

i need to add an arrow to scroll down

<section id="arrow" class="scroll">
  <a href="#services"><span></span>Scroll</a>
</section>
<style>
  .scroll a {
  position: absolute;
  bottom: 20px;
  left: 50%;
  z-index: 2;
  display: inline-block;
  -webkit-transform: translate(0, -50%);
  transform: translate(0, -50%);
  color: black;
  font : normal 400 20px/1 'montserrat', sans-serif;
  letter-spacing: .1em;
  text-decoration: none;
  transition: opacity .3s;
}
.scroll a:hover {
  opacity: .5;
}

#arrow a {
  padding-top: 70px;
}
#arrow a span {
  position: absolute;
  top: 0;
  left: 50%;
  width: 24px;
  height: 24px;
  margin-left: -12px;
  border-left: 1px solid black;
  border-bottom: 1px solid black;
  -webkit-transform: rotate(-45deg);
  transform: rotate(-45deg);
  -webkit-animation: sdb05 1.5s infinite;
  animation: sdb05 1.5s infinite;
  box-sizing: border-box;
}
@-webkit-keyframes sdb05 {
  0% {
    -webkit-transform: rotate(-45deg) translate(0, 0);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    -webkit-transform: rotate(-45deg) translate(-20px, 20px);
    opacity: 0;
  }
}
@keyframes sdb05 {
  0% {
    transform: rotate(-45deg) translate(0, 0);
    opacity: 0;
  }
  50% {
    opacity: 1;
  }
  100% {
    transform: rotate(-45deg) translate(-20px, 20px);
    opacity: 0;
  }
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
  $(function() {
  $('a[href*=#]').on('click', function(e) {
    e.preventDefault();
    $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top}, 500, 'linear');
  });
});
</script>

 


You can send your question to my email to get faster answer. / How to Setup Password & Share URL 

-- I'm Tuan. I work for a non-profit project (promote the establishment of free libraries). I check the forum once or twice a day to help out the community. If you don't see me answering your question, you can send it to the email above. There are so many questions every day so I can't answer them all at once, I will try to answer them in the next few days.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...