With the simple click of a button, I aim to refresh and enhance the appearance of a polygon

My goal is to create a button that, when clicked, causes the gray stripe in the middle to transition to the right. I am not very familiar with HTML, CSS, and JavaScript so I could use some help figuring out how to achieve this effect. Here is a quick illustration of what I have in mind.

Thank you for your assistance.

body
{
    margin: 0;
    padding: 0;
    font-family: 'Open Sans', sans-serif;
    color:white;
overflow:hidden;
font-weight: bold;
  background-image: url('https://i.imgur.com/PSr4n0g.png');
   background-size: cover;
    background-repeat: no-repeat;
  background-attachment: fixed;
}
.Shape{
    clip-path: polygon(25% 0%, 0 0, 75% 100%, 100% 100%);
    position: fixed;
    height: 100%;width: 100%;
}
.ShapeStyle{
    background-color: #20232d;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    filter: opacity(55%);
    z-index: -1;
} 
<link rel="stylesheet" type="text/css" href="1.css">
<link href="https://fonts.googleapis.com/css?family=Montserrat|Open+Sans" rel="stylesheet">
</head>
<body>
<div class="Shape"> 
<div style="height: 80%;width: 60%;margin-left: 10%;margin-top: 10%;">
        <img src="logo.png" height="20%">
        <div class="ShapeStyle"></div>
    </div>
</div>
  
  <div onmouseup="gray()">
  <button class="clicky">CLICK ME!</button>
</div>
  
<div class="background">
          </div>
 </body>
    <script>window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag('js', new Date()); gtag('config', 'UA-73378277-10'); </script>
    <audio id="leson" src="music/music.ogg" autoplay="true" hidden="true" loop="true"/>
<script>


    var play = false;
    var myAudio = document.getElementById("leson");
    
    myAudio.volume = 0.1;


    function onKeyDown(event) {
            switch (event.keyCode) {
                case 32: //SpaceBar                    
                    if (play) {
                        myAudio.pause();
                        play = false;
                    } else {
                        myAudio.play();
                        play = true;
                    }
                    break;
            }
      return false;
    }
    window.addEventListener("keydown", onKeyDown, false);
    </script>
</body>
</html>

Answer №1

If you want to achieve this effect, you can follow the instructions below. One important thing to note is that an additional point needs to be added at the end of the polygon when applying a specific class:

function gray() {
  document.querySelector('.Shape').classList.toggle("clicked")
}
body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans', sans-serif;
  color: white;
  overflow: hidden;
  font-weight: bold;
  background-image: url('https://i.imgur.com/PSr4n0g.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.Shape {
  clip-path: polygon(25% 0%, 0 0, 75% 100%, 100% 100%,100% 100%);
  position: fixed;
  height: 100%;
  width: 100%;
  transition:0.5s;
}
.Shape.clicked {
  clip-path: polygon(25% 0%, 0 0, 75% 100%, 100% 100%,100% 0%);
}

.ShapeStyle {
  background-color: #20232d;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  filter: opacity(55%);
  z-index: -1;
}
<div class="Shape">
  <div style="height: 80%;width: 60%;margin-left: 10%;margin-top: 10%;">
    <div class="ShapeStyle"></div>
  </div>
</div>

<div onmouseup="gray()">
  <button class="clicky">CLICK ME!</button>
</div>

You can also create another type of animation with these steps:

function gray() {
  document.querySelector('.Shape').classList.toggle("clicked")
}
body {
  margin: 0;
  padding: 0;
  font-family: 'Open Sans', sans-serif;
  color: white;
  overflow: hidden;
  font-weight: bold;
  background-image: url('https://i.imgur.com/PSr4n0g.png');
  background-size: cover;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.Shape {
  clip-path: polygon(25% 0%, 0 0, 75% 100%, 100% 100%,100% 100%);
  position: fixed;
  height: 100%;
  width: 100%;
  transition:0.5s;
}
.Shape.clicked {
  clip-path: polygon(100% 0%, 0 0, 75% 100%, 100% 100%,100% 0%);
}

.ShapeStyle {
  background-color: #20232d;
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  filter: opacity(55%);
  z-index: -1;
}
<div class="Shape">
  <div style="height: 80%;width: 60%;margin-left: 10%;margin-top: 10%;">
    <div class="ShapeStyle"></div>
  </div>
</div>

<div onmouseup="gray()">
  <button class="clicky">CLICK ME!</button>
</div>

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

Unable to connect to a style sheet

I'm in the process of developing a web application and I'm facing an issue with linking a stylesheet to my app. Check out my code below: <html> <head> <title>Bubble</title> </head> <link rel=" ...

Looping Feature in Ionic Framework's Slides Component

Currently, I am working on developing an application using Ionic-Angular. When it comes to incorporating slides in my app, I opted for the ionic 4 ion-slides component. Everything was going smoothly until I wanted to enable looping for the slides so that u ...

Ensuring the input element is correctly aligned in its position

How can I center the input element inside its parent without any top margin? What CSS changes do I need to make? #menu { height:30px; background: #ccc; } #board-name { display:block; margin-left:auto; margin-right:auto; height: 80%; vertical-al ...

Is HTML5 local storage not functioning properly on IE11 in Windows 8.1 x64? Encountering an error message:

Is anyone else experiencing this issue where information cannot be found, even though it was previously fixed in a patch a long time ago? Has anyone else encountered this? localStorage.setItem("hello", "somedata"); alert(localStorage.getItem(" ...

Navigation bar's active area does not span the full height

I'm facing some issues with the navigation bar on my responsive website. One issue is that the clickable area for the links does not extend to the full height of the nav bar, and I would like it to cover the entire height. Another problem arises whe ...

Stop treating extra attributes of an Array as elements (in Chrome)

I recently implemented a snippet that enhances Array's functionality by adding a getUnique function: Array.prototype.getUnique = function() { var u = {}, a = []; for (var i = 0, l = this.length; i < l; ++i) { if (u.hasOwnProperty(this[ ...

Importing global variables in Angular SCSS files

Considering a transition to SCSS within my Angular project, I am primarily interested in utilizing the variables feature. Currently, I have been relying on CSS variables, which are conveniently declared in :root in my styles.css file and can be accessed in ...

Apply CSS styling to the entire element when hovering over its pseudo-element 'after'

I am working on a button/speech bubble design with a unique hover effect. Here is the current setup: https://i.stack.imgur.com/4OrpL.png Here is the code snippet for the button: <div value="GO" id="go-div" class="bubble"> <input type="submit ...

The navigation bar text overflows when the sidebar is collapsed into icons

My sidebar contains icons and a menu name. When the screen size is smaller than a certain amount, the sidebar collapses to show only the icon and hides the menu name. Here is the structure of the navbar: <nav id="sidebar" [ngClass]="{active: barActive} ...

Some places may not have detailed information available when using the Google Places API

Greetings I am currently in the process of developing a page on my website that utilizes the Google Places API along with the user's geographical coordinates (latitude, longitude) to locate nearby restaurants. In my code, I have implemented a functio ...

Getting a surprise image from the collection

I am experiencing an issue with retrieving images from an array. I have an array containing 6 variables that represent the paths to the images. However, when I use console.log at the end, it returns a random variable like sk11, sk15, etc., which do not c ...

How to troubleshoot Bootstrap 5 tabs not hiding flex content after tab change?

Bootstrap 5 tab features a Leaflet map that we intend to occupy all remaining space once selected. We managed to achieve this, but now, when switching tabs, the content area of the first tab does not disappear. We suspect that the issue might be related t ...

Error in Node.js: the function "myFunction" is not defined

Utilizing the fcm-node package to facilitate sending notifications from the Express API route to the app via a registration token. The function being used is as follows: const FCM = require('fcm-node'); const serverKey = ... const fcm = new FCM( ...

Caution: Circular dependency has been identified in Angular 10 involving barrels

I keep getting a warning about circular dependencies when using barrelsby in Angular 10. Error: WARNING in Circular dependency detected: src\app\core\components\components.module.ts -> src\app\core\components\hea ...

Comparing tick and flushMicrotasks in Angular fakeAsync testing block

From what I gathered by reading the Angular testing documentation, using the tick() function flushes both macro tasks and micro-task queues within the fakeAsync block. This leads me to believe that calling tick() is equivalent to making additional calls pl ...

Troubleshooting AngularJS UI Router -> Issue with resolution when implementing ui-sref

I have successfully set up a JSON file containing my ui-routes. However, I am encountering difficulties when using the Link functionality. I have managed to use it for the following state: { "name": "home", "url": "^/home", "abstract": false, ...

Hovering in Javascript

Imagine I have the following code snippet: <div class="class1"> ... random content </div> I want to use JavaScript so that when I hover over that div, a CSS attribute is added: background-color:#ffffe0; border:1px solid #bfbfbf; This is a ...

Is it possible to shift the image within the <canvas> element without having to redraw the entire canvas?

I created a game board and I am trying to implement drag-and-drop functionality for my pieces, which are in .gif format. However, I am struggling with finding a solution that allows me to move the pieces without constantly redrawing the entire board. Cur ...

Angular click event not functioning properly on elements loaded via http request

Check out my CodePen link: http://codepen.io/gauravcoder/pen/vLWEjJ?editors=101 I'm just getting started with Angular JS. I have some items that trigger an alert when clicked, it works fine for items that are not loaded via an HTTP request. However, ...

Ordering in D3 Code

I'm struggling with understanding the correct structure for writing D3 code. For example: In the code snippet below, I noticed that if I place the 3rd section (Chart Title) of the code after creating the svg element, the title text doesn't displ ...