Appear gradually in the div with each click

I've created an interactive "click master" that provides feedback on your button clicking skills. Each time you click the button, a random response fades in to judge your click.


"Nice try... but not quite.",
"Weak effort.",
"That was a terrible click.",
"Not up to par.",
"Try clicking lighter next time!",
"Click harder this time!",
"I didn't even feel that.",
"You're getting closer, but still not there.",
"Nope.",
"Improve your clicking technique.",
"Do I need to teach you how to click!?",
"Making progress... almost.",
"This is a definite no.",
"Worst click of the year - 1/10.",
"Why are you deliberately clicking poorly?",
"My grandma clicks better than you, and she's over a hundred years old!",
"Even an AI knows you can't click properly.",
"Maybe your fingers aren't working...",
"Is your mouse stuck or something?",
"Some people have good clicking skills... but not you."
];

$(document).ready(function(){
      $('body').click(function(){
           $(span).addClass('gone');
      });
 });

// DO NOT CHANGE ANYTHING BELOW THIS LINE! //
function newTip() {
  var randomNumber = Math.floor(Math.random() * (ratings.length));
  document.getElementById('quoteDisplay').innerHTML = ratings[randomNumber];
}


<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css">
  <link href="https://fonts.googleapis.com/css?family=Lato|Open+Sans+Condensed:300|Share+Tech+Mono" rel="stylesheet">
  <script src="https://code.jquery.com/jquery-3.2.1.js" integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE=" crossorigin="anonymous"></script>
  <title>THE CLICK MASTER</title>
</head>
<body>
  <h2 class="fadename">THE CLICK MASTER</h2>
  <h6><span>created in about 20 hours by CrashRocks1419 &minus; <a href="../website/main/home.html">Back to my own website</a></span></h6>
  <h1 class="fadeinfo">How well can you click? Get an <span style="border-bottom:6px double black">honest</span> response today!</h1>
  <button onclick="newTip()" id="button">Click me to get a new, <em>helpful</em> tip</button>
  <br>
  <br>
  <div id="quoteDisplay" style="border: 1px solid black;height: 170px;padding:20px;text-align: center;padding-top:110px;">
    <span style="font-family:arial" class="gone">Response appears here...</span>
  </div>
  <script src="javascript.js"></script>
</body>
</html>

Do you think this idea will work as intended?

UPDATE: Typically, the responses just replace the previous text. I would like them to fade out the previous text and fade in the new one if possible.

CSS Styles

.fadename {
  font-family: Courier New;
  animation: fade1 1s ease;
  font-size: 100px;
  font-weight:normal;
  margin-bottom:-30px;
  margin-top:-10px;
}
.fadeinfo {
  font-family: Lato;
  animation: fade1 3s ease;
}
div {
  font-family: Open Sans Condenses;
  font-size: 50px;
  animation: fade 5s ease;
  background: linear-gradient(#716ab2, #94ba92, #f912db);
  background-repeat: repeat-x;
  height: 100%;
  padding: 0;
}
@keyframes fade1 {
  from {opacity: 0;}
  to {opacity: 1;}
}
button {
  font-family: Share Tech Mono;
  color: blue;
  background-color: white;
  animation: fade 1s ease;
  border: 5px solid blue;
  font-weight: bold;
  font-size: 30px;
  transition: box-shadow 0.5s ease, color 0.4s ease, background-color 0.4s ease, border 0.4s ease;
}
button:hover {
  box-shadow: 6px 6px 3px 2px rgba(0,0,0,0.8);
}
button:active {
  color: white;
  background-color: blue;
  border: 5px solid white;
  box-shadow: 1px 1px 2px 1px black inset, 4px 4px 2px 1px black;
}
a {
  color: #111;
  text-decoration: none;
  font-weight: bold;
}
html {
  background: linear-gradient(#8abc3d, #ba72dd);
  background-repeat: repeat-x;
  height: 100%;
  padding: 0;
  background-color: #ba72dd;
}
b, a {
  color: #f22;
}
.twoline {
  font-size: 37px;
  top: -200px;
}
.gone {
  opacity: 0;
  animation: gone 3s ease forwards;
}
@keyframes gone {
  10% {opacity:0;}
  20% {opacity:0;}
  30% {opacity:1;}
  40% {opacity:1;}
  50% {opacity:1;}
  60% {opacity:1;}
  70% {opacity:1;}
  80% {opacity:1;}
  90% {opacity:1;}
  100% {opacity:0;}
}
h2 {
  width: 980px;
}

Answer №1

One way to implement this functionality is by utilizing the fadeToggle() method in jQuery:

function newTip() {
  var randomNumber = Math.floor(Math.random() * (ratings.length));
  $('#quoteDisplay span').fadeToggle("slow", function() {
    $(this).html(ratings[randomNumber]);
    $(this).fadeToggle();
  });
}

For more information on how to use this feature, you can refer to the official documentation.

Here is the full code snippet for your reference:

var ratings = ["That was a nice click... I guess.",
  "Wimpy.",
  ...
  "<span class=\"twoline\">There are people who can click well... and unfortunately, you're not one of them.</span>"
];

// DO NOT MODIFY ANYTHING BELOW THIS POINT! //
function newTip() {
  var randomNumber = Math.floor(Math.random() * (ratings.length));
  $('#quoteDisplay span').fadeToggle("slow", function() {
    $(this).html(ratings[randomNumber]);
    $(this).fadeToggle();
  });
}
<!DOCTYPE html>
<html>

<head>
  <link rel="stylesheet" type="text/css" href="style.css">
  <link href="https://fonts.googleapis.com/css?family=Lato|Open+Sans+Condensed:300|Share+Tech+Mono" rel="stylesheet">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
  <title>THE CLICK MASTER</title>
</head>

<body>
  <h2 class="fadename">THE CLICK MASTER</h2>
  ...
  </div>
  <script src="javascript.js"></script>
</body>

</html>

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

SystemJS could not locate the root directory for RxJS

There seems to be an issue with SystemJS loading rxjs modules on Windows, as it throws a 404 Not Found error on the rxjs directory. This problem does not occur on OSX, and all modules are up to date. GET http://localhost:8080/node_modules/rxjs/ 404 (Not F ...

The jQuery code is failing to run as intended

Recently, I encountered an issue with a HTML page that utilizes some jQuery libraries. The specific functionality in question involves a balloon floating across the screen, which works perfectly fine on my local machine. However, upon integrating this pag ...

Alter the entity type when passing it as a parameter

Trying to alter the Entity type, I am invoking a function that requires two parameters - one being the entity and the other a location. However, when trying to assign a Type for the first entity, it throws an error: Error: Argument of type 'Node<En ...

js simulate a click on an anchor element based on the child element's id

I am trying to automatically trigger a click on an a tag that contains a div with the id='a'. $(document).ready(function() { $("#chat_list_content a:has(div[id='a'])").click(); //$("#chat_list_content a:has(div[id='a']) ...

Unable to execute commitlint in husky along with a different custom command

Is it possible to set up two precommit hooks with husky? Specifically, I want to integrate commitlint along with a custom script specified in my package.json. After installing husky and creating a pre-commit script in the .husky folder, here is what I have ...

What is the best way to send Nested JSON data to a controller in MVC5?

I'm new to developing MVC Web Applications. I am attempting to send nested JSON data to a controller in MVC, but I am encountering issues with passing the JSON file. Here are my models: public class SurveyViewModels { public string Ques ...

Access a webpage outside of your domain using htaccess and PHP functionality

When a request is made to my website like this: my1stdomain.com/request-1/ my1stdomain.com/any-another-request/ The corresponding web pages should open on: my2nddomain.com/folder/request-1.php my2nddomain.com/folder/any-another-request.php To achie ...

Working with JSON arrays in Watson Assistant: add and edit functionality

Currently, I am delving into the world of Watson AI/Assistant in order to incorporate it into our services as a web development firm. To enhance my understanding of the assistant, I have embarked on a self-taught journey by creating a text-based adventure ...

Error message found: "Uncaught TypeError: e[n] is undefined while setting up redux store in a reactjs application

Delving into the world of Redux for the first time, I decided to tackle the Todo List example from the official redux.js.org website. After testing the code, everything seemed to be working fine with the redux store initialized only with the reducer as a p ...

How to Position Two Child Divs in the Center of a Parent Div

I have been searching extensively, but I can't seem to find a solution to my problem. Let me explain with a simple example. I have two child div elements within a parent div, and I want them to be centered horizontally inside the parent div. Here is t ...

Capybara: identifying CSS that contains a specific attribute with no value associated (for example, finding <img alt>, but not <img alt=""> or <img alt="x">)

Following the update of Pandoc from v1.19 to 2.9, I find myself in need of making changes to some of my specifications. In the past, the following assertion was valid: expect(page).to have_css('.figure img[src="decorative-image"][alt=""])' Now ...

Necessary workaround needed for HTML time limit

Our HTML page has been designed to automatically timeout after 10 minutes of inactivity. This functionality is achieved through the following code: function CheckExpire() { $.ajax({ type:'GET', url:self.location.pathname+"?ch ...

Exploring criteria in mongodb

user.js exports.searchProducts = async (productName, productBrand) => { let queryFilters = { productName, productBrand } // ====>>> if productBrand or productName is = '' then it does not search queryFilters = JSON.parse(JSON.stri ...

The event listener for 'annotations.create' in the PSPDFKIT instance does not include the required annotation type

I'm facing difficulties with integrating pspdfkit to properly create and display my annotations. My goal is to create annotations in the following manner: instance.addEventListener("annotations.create", createdAnnotations => { ...

Don't forget the last click you made

Looking for a way to style a link differently after it has been clicked and the user navigates away from the page? Check out this code snippet I've been using: $(document).ready(function(){ var url = document.URL; function contains(search, find) { ...

AngularJS restricts inputs to be read-only

I'm facing an issue with readonly inputs in AngularJS. I have a select element that changes the values of readonly inputs through a script. However, when I attempt to display these values using ng-model in a table as {{ng-model}}, they don't appe ...

Looking to obtain rendered tree data upon page load?

Is there a way to retrieve all rendered tree metadata when the page loads using jstree? I'm looking for an output similar to this: [23,24] Please note that I would like to have each id stored in the metadata object displayed as [23,24] upon page loa ...

How can I retrieve text instead of HTML using jQuery.get?

I'm facing an issue where I am trying to retrieve data from another site using the code below: jQuery.ajaxSetup({ crossDomain: true, dataType: "jsonp text" }); jQuery.get(url, function(rawContent) { console.log(rawContent); }); However, ...

The world of coding comes alive with Quartz Composer JavaScript

Seeking assistance as I navigate through a challenging project. Any help would be greatly appreciated. Thanks in advance! I have a Quartz Composition where I aim to incorporate a Streetview from Google Maps and control the navigation, but I'm unsure ...

Authentication through Auth0 login

After successfully registering a user in Auth0 for login purposes (found in the Users section of the dashboard), I implemented the following code to authenticate the user using an HTML form with username and password fields: public login(username: string, ...