So, I'm working on a jQuery code snippet that controls the visibility of a rectangle element:
$("#rectangle").hide();
$("#toggle-rec").click(function () {
$("#rectangle").toggle(2000);
});
This code hides the rectangle initially and toggles its visibility whenever the button with id #toggle-rec
is clicked. However, I want to implement a feature where, if the rectangle is shown, it will add padding-left of 200px to the entire website (except for the rectangle) to accommodate the width of the rectangle.
Currently, I am unsure of how to achieve this. Additionally, when the rectangle disappears, the added padding should be removed. Any ideas on how to accomplish this?
Note: The content of the website excluding the rectangle is wrapped within a div.
Here is a snippet of my HTML structure for reference:
<div id="rectangle">
Some text on the rectangle...
</div>
<div id="wrapper">
<!-- Various other elements go here... -->
<button id="toggle-rec">Toggle rectangle</button>
</div>