Concealing a message within a section that has been minimized to a width of 0

Recently, I've encountered a challenge in attempting to set the width of a section to 0 and have all its contents also disappear. Despite changing the section's width to 0px, the text inside continues to be displayed and even shifts off to the side. Is there a way to utilize either CSS or JavaScript to hide the text and then reveal it when the section's width returns?

If you want to take a look at the code on jsfiddle, here's the link: http://jsfiddle.net/t6ck9ajb/

$(document).ready(function(){
        $("#about").click(function(){
        if ($("#about-me").css("width") <= "0vw") {
            $("#introduction").animate({width:"0vw"}, 500);
            /*$("#intro").css("display","none");
            $("#port").css("display","none");
            $("#about").css("display","none"); */
        }
        else {
            $("#introduction").animate({width:"0vw"});
        }
        });
        });

Although this is my attempt at hiding the text, it didn't work as expected.

Answer №1

Presenting an alternative method:

$(function(){
  $('#about').on('click', toggleHomeAbout);
  $('#home').on('click', toggleHomeAbout);
});

function toggleHomeAbout(){
  $('#introduction').toggleClass('active');
  $('#about-me').toggleClass('active');
}
* {
margin: 0px 0px;
padding: 0px 0px;
font-family: "Open Sans";
}

#container{
    width: 100vw;
height: 100vh;
    overflow:hidden;
    position:relative;
}
...
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
    <div id="container">
<section class="full-page right" id="about-me">
<h1 id="information">About Me</h1>
<a id="home">Back home</a>
</section>
<section class="full-page left active" id="introduction">
<h1 id="intro">Hello, my name is<br/><span class="big">Michael!</span>  </h1>
<a id="port">Portfolio</a>
<a id="about">About Me</a>
</section>
    </div>
</body>

Answer №2

One simple way to conceal the content when the '#about' selector is activated is by employing the $('#introduction').toggle() method.

Answer №3

The problem is related to CSS. To resolve it, you should include the line overflow: hidden; in the section where you want content to be concealed when the width changes, specifically within the element #intro.

Answer №4

Check out this demo for the proposed animation: demo

Cascading Style Sheets (CSS):

#introduction {
    z-index: 1;
    visibility:"visible";
    overflow:hidden;
}

jQuery Code:

$(document).ready(function () {
    $("#about").click(function () {
        if ($("#about-me").css("width") <= "0px") {
            $("#introduction").animate({
                width: "0px"
            }, 500, function () {
                $("#introduction").css("visibility", "hidden");
            })
        } else {
            $("#introduction").animate({
                width: "0px"
            });
        }
    });

});

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

The Lenis smooth scrolling feature (GSAP) is not functioning properly

I have encountered an issue with the smooth scrolling feature of gsap causing a delay on my website. This problem is only resolved when I manually go into the browser settings and disable smooth scrolling by navigating to chrome://flags/#smooth-scrolling ...

Enhancing the functionality of a bootstrap button with the addition of an

My goal is to have a button that opens a URL in a new tab. I've managed to achieve this using window.location.href, but it doesn't open the URL in a new tab. The code I'm working with is written in jQuery and Javascript, and it's part ...

Unexpected behavior observed with LitHTML when binding value to input type range

Currently, I am working on an implementation that involves using range inputs. Specifically, I have two range inputs and I am trying to create a 'double range' functionality with them. The challenge I am facing is related to preventing one slider ...

Acquiring the Facebook profile_id and incorporating it into a URL using a Chrome Extension

Although I have limited knowledge of JavaScript, I believe I know enough to complete the task at hand; I just need some guidance. I am working on developing an extension that will extract the profile_id from the current Facebook page being viewed, and the ...

angular and node: troubleshooting the $http.get error

I have encountered an issue with the $http.get instruction. Without it on the main page, I receive a result of "random 46" which is correct. However, when I include $http.get, I get a result of "random {{ number }}". How can this problem be resolved? -se ...

Conflict with choosing options identified when using Select Box on IOS iPad mini

I am currently attempting to display a select box with scrolling on an iOS iPad mini. Issue: The options are not appearing inside the select box, instead they are overflowing outside of it in the popover. CSS .indicators_geography { font-size: 12px; ...

Unable to display divs in a stacked format using Bootstrap 5

I need help aligning div's vertically on the page. Currently, all my elements are displaying next to each other instead of stacking one below the other. body { height: 100vh; } <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi ...

Troubleshooting Issue with Jquery AJAX Loading

I have been experimenting with loading all my website pages using jQuery's .load method. Here is the code I am currently using: <script type="text/javascript"> $(function() { $('.link').bind('click', function(e) { ...

Can you explain the variance in these code snippets when implementing React's setState() function?

Can you explain the variance between these two blocks of code? this.setState((state)=>({ posts: state.posts.filter(post=> post.id !==postRemoved.id) })) versus this.setState((state)=>{ posts: state.post ...

Dynamically load content onto a jQuery Mobile page upon clicking a link

I'm relatively new to working with jQuery Mobile and making AJAX requests. Let me try to explain my issue clearly. Currently, I am developing a mobile project and utilizing the jQuery Mobile auto-complete list, populating it with data from an XML fil ...

Using the useState hook in a loop can sometimes result in a unique key error

Trying to add multiple items for rendering in my browser, but encountering an issue after clicking addItem. The item does render, however, I am getting the following error message: 'Warning: Each child in a list should have a unique ""key"" ...

What is the best way to share both text and an image URL in a single tweet through the Twitter API

Currently, I am utilizing the Twitter API Client for node which includes both the REST and Streaming API. You can find more information about this client by visiting this link. Specifically, I am working with the twit API in conjunction with nodejs. My go ...

The challenge of populating information within a Datalist

In my code snippet, I have a JavaScript function that is used to populate a Datalist: function PopulateDropDown(facility) { $.ajax({ url: '/Rentals/Base/GetContactsForFacility?selectedFacility=' + facility, data: { facility: ...

The jQuery function that clears the form data

I have a webpage where clicking on a link changes the content of a div using the following code. The content is filled out using page1.php, which includes a form with dropdown lists. However, whenever I try to select something from a dropdown list, it res ...

Locate the unique symbol within an array

I am facing a challenge with validating user input in an input box where alphanumeric values are allowed along with certain special characters. I need to display an error message if the user enters a special character that is not supported by my applicatio ...

Use JSON data to populate a dynamic bar chart in Highcharts

As a beginner in parsing JSON objects to highcharts, I am trying to create a basic bar graph. I have managed to set up the title of the graph, but I am having trouble displaying the series that I want to show (count as series and qpAnswer as xAxis). Below ...

"Discover the method for tallying the quantity of radio buttons based on their names within AngularJS

Can anyone guide me on how to determine the number of radio buttons by name in AngularJS using a directive? <label ng-repeat="elements in [1,2,3,4,5,6,7]"> <input type="radio" name="phone" ng-model="phone" value="example"> </label& ...

Is it possible to leverage Create-React-App's npm start in conjunction with Node.js?

I've recently started diving into React and node.js. My goal is to have a node.js server that can serve up React.js pages/views. After running 'create-react-app' and then using 'npm start', I'm not sure if I also need to man ...

Issue: Troubleshooting data serialization process using getStaticProps in Next.js

I attempted to retrieve data from an API, but unfortunately encountered the following error: Server Error Error: Issue with serializing .results returned from getServerSideProps in "/". Reason: JSON serialization does not support undefin ...

Discrepancy in CSS rendering in Chrome and Firefox

When viewing in Chrome, the stats display properly within the gray box at the bottom left corner. However, when using Firefox, the stats appear positioned much lower below the box, with the bottom half of them hidden from view. Here is my CSS code being ...