The functionality of jQuery .Show() may be affected when a negative margin is present in the

Check out this demo on Codepen that showcases the issue: http://codepen.io/theclarkofben/pen/xKhsd

The .Show() effect isn't working as expected due to the negative margin applied to the div.

Can someone shed light on why this behavior is occurring?

Is there a way to utilize negative margin with this approach without encountering issues?

I'm using Chrome and have tested different versions of jQuery and jQuery UI, but the problem persists.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed nec velit leo. Phasellus non erat nulla. Fusce hendrerit justo vitae purus suscipit non ac nisl. Nam eu ligula risus. Duis sed felis at tortor fermentum fermentum vel eget nibh. Maecenas porttitor magna augue, vel luctus tellus blandit convallis. Donec feugiat sollicitudin ornare. Integer efficitur pellentesque malesuada. Integer sodales rutrum neque quis fermentum. Vivamus et nisi accumsan, vestibulum sem eu, ultricies eros.

Answer №1

By clicking on a button, you can adjust the CSS property margin-right to 300px and then reset it to -300px in a callback function. This functionality has been tested and is functioning correctly. I hope this meets your requirements! Check out this example on codepen.

  $(function() {
    // run the currently selected effect
    function runEffect() {
      // get effect type from
      var selectedEffect = "clip";

      // most effect types need no options passed by default
      var options = {};
      // run the effect
      $(".about_me").css("margin-right", "300px");
      $("#show_effect").show(selectedEffect, options, 500, callback);
    };

    //callback function to bring a hidden box back
    function callback() {
      setTimeout(function() {
        $("#show_effect:visible").removeAttr("style").fadeOut();
        $(".about_me").css("margin-right", "-300px");
      }, 1000);
    };

    // set effect from select menu value
    $("#about_me_button").click(function() {
      runEffect();
    });

    $("#show_effect").hide();
  });
.about_me {
  width: 600px;
  height: 225px;
  margin-right: -300px;
}
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<button id="about_me_button">About Me</button>
<div id="show_effect" class="about_me">
  <p>Quis vivendum ei vim, ut alia essent persequeris ius. Et sed diam harum consul, ut usu admodum appareat...

Answer №2

Alright..

After some research and considering your query about using negative margin, I have devised two potential solutions for you to try out...

1 - Instead of margin-right:-300px, use margin-left:300px - This adjustment can eliminate any flickering effect while achieving the same outcome.

.about_me {
  width: 600px;
  height: 225px;
  margin-left:300px
}

2 - Create a parent container for <div class="about-me"> and apply margin-right:-300px styling to it.

Access the code snippet on Codepen here : http://codepen.io/anon/pen/zHfbD Review the HTML structure below:

<div class="about_me_container">
  <div  id="show_effect" class="about_me">
     <p>Information about myself will be displayed here</p>
  </div>
</div>

CSS Details:

.about_me {
  width: 600px;
  height: 225px;

}

.about_me_container{
  margin-right:-300px;
}

I hope these suggestions prove useful in resolving your issue!

Best regards, RP

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

Prevent a HTML button from being clicked multiple times before it disappears (using Django)

I am currently working on a Django project that involves events where users can join by adding their user_id and event_id to the attend model. On the event page, there is a join button form that, when clicked, adds the user to the attendees list. After cli ...

The expected behavior of first-child is not impacting the initial element as anticipated

What is the reason behind the rule not impacting the first div containing the "update 1" text? .update div { width:100%; height:25%; border-top:1px dashed {color:background title}; padding: 5px; color:{color:links nav}; cursor:po ...

Issue with confirming deletion of tabulated records

HTML Code: <td>random_data_1</td><td><button id="random_data_1"></button></td> <td>random_data_2</td><td><button id="random_data_2"></button></td> <td>random_data_3</td ...

Retrieving form data using query parameters in Flask

Here's my initial question, so please let me know if I've overlooked anything ;) I'm in the process of developing a website that will execute Python code to solve a specific problem and display the outcomes as numerical values and a plot on ...

Is it possible to decrease the size of a div by scrolling both vertically and horizontally?

Can a div's height and width both be reduced at the same time while scrolling down a page? Let's say that as the user scrolls, the size of the div changes from 400px by 400px to 200px by 200px, all while remaining centered on the page. I've ...

Is there a way to expand the clickable area of JQuery sliders?

Check out some of the jquery ui sliders here One issue I am facing is that when you click the slider bar, the tic jumps to that exact part. This can be problematic because the bar is quite thin, making it easy to miss when trying to click on it. I want to ...

The system of jQuery Dialog UI is unable to recognize when the close icon is clicked

How can I detect if a user closes my dialog modal box using the 'X' button in the upper-right corner of the titlebar? I've been struggling to find a solution while using jQuery's Dialog UI plugin. Here is what I have tried so far: $(&a ...

The Quivering Quandaries of Implementing Jquery Accordions

For a demonstration of the issue, please visit http://jsbin.com/omuqo. Upon opening a panel by clicking on the handle, there is a slight jitter in the panels below during the animation. In the provided demo, all panels should remain completely still as t ...

Activate the parent navigation link when on sub-pages

I want to ensure that the parent navigation item is highlighted when a user is on a child page based on the URL. For example, if the user is currently viewing foo1-child and the parent is foo1, I need to apply the active class to Foo 1: http://foo.com/foo ...

All menus effortlessly sliding out simultaneously

I'm having an issue with my navigation bar. I want each link to slide its corresponding DIV up or down when clicked. However, all the DIVs are sliding and when clicking on the same link everything slides up. How can I fix this problem? This is my HT ...

The dynamic data is not displaying on the Chart bundle JavaScript

I am currently utilizing chart bundle js for my project. While everything appears to be functioning properly on alter show, I am encountering an issue with the map display – nothing is showing up as intended. If anyone has a solution to resolve this iss ...

Step-by-step guide on how to configure the URL path in an AJAX function call

How can I dynamically set the URL path in an AJAX function call when clicking on a page so that the page name is included in the URL? For example, if I click on a particular page (let's say the "ask" page on Stack Overflow), the URL should look like: ...

If an element with a "hidden" display property is loaded in the browser window, will it be visible?

Is an element in a hidden display still using memory when the page is loaded? It's convenient to have many elements on a page, but if 99 elements are hidden and only 1 is displayed, does that impact the loading of the page? I'm curious if the pa ...

Unable to display jQuery modal due to error "Uncaught DOMException: Failed to execute 'appendChild' on 'Node': The new child element contains the parent."

Check out the JS Fiddle demo here. Here is the code in question: $('#infoTable').click(infoModal); function infoModal(){ var table = "THIS IS A TABLE"; $("#dialogContainer").dialog({ appendTo: "#msg-dialog", autoOpen: f ...

I'm puzzled as to why the hidden input field consistently returns the same value every time

As a beginner in php, I am facing an issue where I cannot trace the correct value of the hidden input which represents the ID of the image in the products table. Every time I try to delete an image, it always returns the ID of the last image in the product ...

Utilize the power of AJAX for efficiently sorting search results retrieved from MySQL

I'm in the process of designing a flight search page. The initial page contains a form, and when the submit button is clicked, the search results are displayed on the second page. Here's the link to the first page: To test it out, please follow ...

Incorporating fresh visuals into the Fotorama presentation

Currently in search of a reliable jQuery image slider with thumbnail previews for a web application I am developing. Initially interested in Fotorama.js as it meets most of my criteria, but unsure if it supports adding additional images via AJAX after in ...

After clicking multiple times within the modal, the modal popup begins to shift towards the left side

I successfully implemented a modal popup in my project, but encountered an issue where the popup moves to the left side if clicked multiple times. Despite searching extensively online, I have not been able to find a solution to this problem. Below is the ...

Tips for customizing the event target appearance in Angular 2?

After following the steps outlined in this particular blog post (section 3, event binding), I successfully added an event listener to my component class. I can confirm that it responds when the mouse enters and exits. <p class="title" (mouseenter)="unf ...

Using the Backbone.js library to make secure requests over https

Currently, I am developing a single page application that involves using Backbone.js and Marionette on the front end, combined with Django and Tastypie on the back end. Recently, I successfully implemented an SSL certificate on the web server and configure ...