Adding animation to the triangular icon at the bottom

I am trying to animate a triangle at the bottom of the screen into view from the bottom when a specific class is applied to it.

css

.fade-in { bottom: -30px; }
.btn-visible.fade-in #top-btn-BG { bottom: 0; }

#top-btn a {
 position: fixed;
 z-index: 999;
 padding: 30px 30px 25px 25px;
 color: #707070;
 bottom: 0; right: 0;
}

#top-btn-BG {
  display: block;
  position: fixed;
  z-index: 950;
  border-width: 0 0 125px 125px;
  border-color: transparent transparent #fff transparent;
  border-style: solid;
  right: 0;
  width: 0; height: 0;
  -webkit-transform:rotate(360deg);
}

html

  <div id="top-btn" class="flex fade-in">
    <a href="javascript:void(0);" onclick="scrolltop();"><i class="fa fa-long-arrow-up fa-lg"></i></a>
    <div id="top-btn-BG"></div>
  </div>

php

jQuery(document).ready(function($){

// adjust this number to select when your button appears on scroll-down
var offset = 300,
scroll_top_duration = 3000,

// bind with the button link
$animation = $('.fade-in');

// apply animation
$(window).scroll(function(){
    ( $(this).scrollTop() > offset ) ? $animation.addClass('btn-visible') :
    $animation.removeClass('btn-visible');
});

...

The code successfully adds the btn-visible class to .fade-in when the user scrolls, but I am struggling to get the animation to work. I need help figuring out where to apply transition css to ensure the entire #top-btn div animates up or down smoothly.

Answer №1

The concept of top-btn-bg is somewhat perplexing as it seems to be invisible in nature. It would be more logical to transfer your positioning and class modification to the main container for the button and adjust the order so that later declarations take precedence. Here's a revised version...

#top-btn {
 position: fixed;
 z-index: 999;
 padding: 30px 30px 25px 25px;
 color: #707070;
 bottom: -30px; 
 right: 0;
}
#top-btn.fade-in{
  bottom: 0;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoiding errors caused by refreshing the page when submitting a POST form

What can be done to prevent a resubmission prompt when refreshing a page that has a registration form submitted using the POST method? ...

Center column with header and footer flanking each side

Trying to replicate the layout of the Facebook Android app on my page. The app features a 3 column design, with the central column exclusively displaying the header (no footer included, although I require one for my version). This visual representation is ...

Attempting to create a dynamic layout for the objects using media queries and flexbox, however, the results are not as expected

.container { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; flex-direction: column; } .item { margin: 10px; border: 1px solid lightgray; border-radius: 10px; overflow: hidden; width: 100%; } @media scree ...

The button appears to be unresponsive

I've been struggling to figure out why the 2-minute/5-minute buttons are not working as expected. Despite identifying some mistakes in my code, nothing seems to change when I test it. There are no error messages either, so I'm hoping someone can ...

How is it possible that the form already comes with data filled in that I didn't input myself

I am currently working on a website using cakephp. Strangely, when I load the login form, both the username and password fields are already prefilled. The interesting part is that this information is not hardcoded anywhere in the form or controller files. ...

Updating the CSS properties of a specific element within a dynamically generated JavaScript list

So I'm working on a JavaScript project that involves creating a navigation bar with multiple lists. My goal is to use the last list element in the bar to control the visibility (opacity) of another element. So far, I have been using the following code ...

Updating padding through local storage does not function as intended

I recently added two buttons to my website for adjusting the padding. While they are functional, I find myself manually setting the padding for nav, main, and footer in the CSS. Here is the snippet of the code: main { padding: 20px 25%; } footer { ...

The cross-domain AJAX request fails to receive a response

I am currently working on validating PAN card details. I am utilizing an AJAX call to verify the PAN card entered by the user, sending the PAN number to this URL: . The data is being sent to the following URL using AJAX call: function callbackFnc(data) { ...

How can you check if a field is blank without allowing any empty spaces to be saved in JavaScript?

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <html> <body> <form id="api_crud_form" name="api_crud_form" action="https://www.google.es"> Name: <input type="text" name="name" id=" ...

What is the best way to align this list horizontally with evenly distributed widths?

I am struggling to figure out how to turn this into a horizontal list where all the elements have equal width. If there is any missing information, please let me know by commenting or messaging. All the CSS that is not within the "grid" <li> is for ...

Send data to a PHP script with $.post() method and receive the results using $.getJSON

I'm attempting to incorporate the $.getJSON function within a $.post function in order to retrieve data and display the returned value in a textbox with the id of 'desc'. Below is my current code: function dataload(){ var currentId = $( ...

What is the best way to position text at the bottom of an image using CSS?

Utilizing the jQuery Caption Plugin to showcase the image alt text when hovering over an image. Currently, the text is displaying at the top but I would like it to show at the bottom. Any suggestions on how to remedy this? Desired Outcome: Check out the ...

Dynamic CSS manipulation with jQuery: Generate and access styles on the fly

I am working on an application where I am utilizing jQuery along with maphilight for highlighting image map segments. In addition to this functionality, I want to dynamically highlight specific HTML elements based on mouseover/mouseout events for the image ...

What is the best method for deleting the 'records per page' label text from datatables?

I'm trying to customize my jQuery datatables by removing the label "Records per page." I already know that "oLanguage": { "sSearch": "" } can be used to remove the search label, but is there a similar option for hiding the results per page label? ...

Identify and forward to the mobile-friendly version of the site

I am currently working on a website that requires separate files for mobile view as the html layout poses challenges in making it responsive. My goal is to find code that can detect if the user is accessing the site from a mobile device, and automatically ...

Obtaining output values from a POST request

When making a GET request through Ajax using jQuery, the URL displayed in the Chrome console is script.php?param=1. $.ajax({ type : "POST", url : "script.php", data : { q : "save", query : query // a variable }, succe ...

Is there a way to automatically highlight an input field upon page load?

Is there a way for certain websites to automatically highlight an input field upon entering a page? For instance, YouTube's login page automatically highlights the Username field as soon as you land on it. Even this site, particularly on the Ask Ques ...

Issue in Wordpress: ReferenceError - '$' is not defined

Currently utilizing WordPress and attempting to access the following code snippet. I am encountering an error on the last line }(jQuery)); (function($) { $(function () { // Slideshow 3 $("#slider3").responsiveSlides({ auto: true, pag ...

AngularJS attempting to conceal the popup menu upon clicking outside of the designated area

My HTML structure looks like this: <div> <a href="" ng-click="$scope.show_menu = !$scope.show_menu">Options</a> <div class="options_box" ng-show="$scope.show_menu"> <button>Option1</button> ... ...

"Hiding elements with display: none still occupies space on the

For some reason, my Pagination nav is set to display:none but causing an empty space where it shouldn't be. Even after trying overflow:hidden, visibility:none, height:0, the issue persists. I suspect it might have something to do with relative and ab ...