The constant motion of jQuery images is mesmerizing

Having trouble with a slide effect in my project. I have set up 4 images, where images 3 and 4 should slide down when clicked. Additionally, a div element should come down from them. I'm new to this, so apologies if it's a simple question. Any assistance would be greatly appreciated.

IMAGE 1 IMAGE 2

IMAGE 3 IMAGE 4

However, clicking on image 1 causes all the images to move unexpectedly. Image 2 works as intended (images 3 and 4 slide down with the div). Image 3 also behaves correctly. But when clicking on Image 4, all images move except for image 4 which ends up in an odd position.

CSS Styling:

.image1{position:relative;top:-10px;left:-10px;margin:10px;}
.image2{position:relative;top:-10px;left:25%;margin:10px;}
.image3{position:relative;top:0px;left:-10px;margin:10px;}
.image4{position:relative;top:0px;left:25%;margin:10px;}

body{left:20%;width:60%;height:110%;padding:10px;
     background-color:white;position:absolute;
     margin:0px;opacity:0.9;filter:alpha(opacity=90);
      /* For IE8 and earlier */-webkit-box-shadow:  6px 6px 50px 5px rgba(0, 0, 0, .5);
     box-shadow:  6px 6px 50px 5px rgba(0, 0, 0, .5);
    border-radius:4px;
    background-color:#0033ff;}

#panel,#panel2,#panel3,#panel4{
display:none;padding:400px;margin:auto;}

#panel,#flip,#panel2,#panel3,#panel4,#flip2,#flip3,#flip4{
padding:5px;text-align:center;background-color:#e5eecc;
border:solid 1px #c3c3c3;}

HTML Code

<img src = "pics/dog.jpg" id="flip" class ="image1"/>
<div id="panel">Hello world! test one</div>

<img src = "pics/dog.jpg" id="flip2" class ="image2"/>
 <div id="panel2">Hello world! test two</div>

<div id="panel3">Hello world! test three</div>
<img src = "pics/dog.jpg" id="flip3" class ="image3"/>

<div id="panel4">Hello world! test four</div>
<img src = "pics/dog.jpg" id="flip4" class ="image4" />

Javascript Script:


<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script> 
$(document).ready(function(){
  $("#flip").click(function(){
    $("#panel").slideToggle("slow");
  });
});
</script>
  <script> 
$(document).ready(function(){
  $("#flip2").click(function(){
    $("#panel2").slideToggle("slow");
  });
});
</script>
<script> 
$(document).ready(function(){
  $("#flip3").click(function(){
    $("#panel3").slideToggle("slow");
  });
});
</script>
<script> 
$(document).ready(function(){
  $("#flip4").click(function(){
    $("#panel4").slideToggle("slow");
  });
});

Answer №1

Initially, stick to a single script tag with just one ready(). It seems like the issue lies within your CSS. Refer to this resolution provided in a JSFiddle, assuming I've grasped the problem accurately.

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

Transform the usual button into a jQuery button that requires a press and hold action

Within my code, there are two buttons in play. One button triggers the burger menu, while the second button adjusts the size of a div. I am looking to transform only the second button into a hold button that activates after a 3-second delay. code: $doc ...

Adjusting the Bootstrap button block to match the width of the screen

Can anyone help me with this issue? My Bootstrap button is extending outside the screen and I'm not sure how to fix it. Here is the link to my plunker <div class="bigone"> <div class="mybar">Nav bar</div> <div class="m ...

Hide the 1, 2, 3 page buttons in Datatables pagination and instead display only the Next and Previous buttons for navigation

I recently implemented datadables.net pagination for my HTML table. I am looking to customize the pagination buttons by hiding or removing the 1, 2, 3 ... buttons and only display Next and Previous Buttons. Is there a way to achieve this by setting paging ...

What is the best way to align this form perfectly in Bootstrap 4?

HTML <div class="container-fluid background"> <div class="row"> <!-- background effect --> <div id="particles-js"> <div class="login col-12"> <form class="login-form" method="post" action=""> ...

Strategies for transferring data from JavaScript to Express for seamless integration as a default value

I am currently utilizing express, MongoDB for the database, and EJS. I am in the process of developing a form that allows users to submit a new article for a blog. The goal is for the website to redirect back to the page with the form fields populated if a ...

Struggling to align a button in the middle of an HTML form using flexbox - see code snippet below

Hey everyone, I’m having trouble with centering my button within the flexbox container with the class "hero". Any thoughts on why this might be happening? The button appears below the email form but is aligned to the left of it (starting at the same pos ...

Type the vinculum symbol above a number using HTML

As a Blogger, it is crucial for me to be able to write bars above numbers. Despite numerous searches on Google, there seems to be a lack of articles addressing this specific need. Most of the resources available focus on putting bars above letters or tex ...

JSON calls that can be made across different domains

Similar Question: Ajax cross domain call I am facing an issue with calling Asp.Net Controller methods that return JSON responses from a different domain. Even when using Jquery's $.getJSON(...){}, I am encountering difficulties. After some quick ...

Ways to add style to Chrome without causing any changes in Edge

I'm working on fixing a bug in Chrome and have successfully applied a style to correct it. However, when I view it in Edge, the appearance is not right. How can I target only Chrome (version 60) with my styles, without affecting other browsers? @medi ...

Press the button to reveal the hidden Side Menu as it gracefully slides out

I'm interested in creating a navigation menu similar to the one on m.facebook.com, but with a unique animated slide-out effect from the left side of the website. Here's the flow I have in mind: Click a button > (Menu is hidden by default) Men ...

JavaScript mouse and touch movement events (mousemove, pointermove, touchmove) are not always accurate

I'm currently working on developing a JavaScript whiteboard and have implemented the following code: let lastTimestamp = 0; const fps = 1000/60; document.addEventListener("pointermove", moveMouse, false); function moveMouse (e) { e.preve ...

Displaying images in a horizontal row instead of a vertical column when using ng-repeat

I am currently using ng-repeat to showcase a series of images. While I believe this may be related to a CSS matter, I am uncertain. <div ng-repeat="hex in hexRow track by hex.id"> <img ng-src="{{hex.img}}"/> </div> https://i.sstatic ...

Sorting through mongoose information on the front end using EJS depending on a dropdown pick

Beginner embarking on my inaugural project here. I have developed 2 Mongoose schematics and models for managing categories and products. The products are nested within the corresponding categories model. Using Node and Express, I successfully sent all ca ...

CSS styles not displaying correctly - malfunctioning (unusual)

Trying to tackle this issue, but feeling a bit lost. Whenever I resize the site below 1600px, everything breaks despite having media queries in place to handle the changes. One particular problem that's baffling me is related to a logo in an id that s ...

What is the proper way to insert a video using html5?

Hi there! I've been working on creating a webpage and have successfully added all other elements except for embedding a video using html5. It is crucial to the overall design of my website, so any assistance you can provide would be greatly valued. ...

Model change event in Backbone not triggered following model setting

I tried a different approach and used $.ajax() for an ajax file upload because I couldn't quite figure out the "backbone" way at the moment. The new picture has been successfully uploaded and the ajax request returns the new backbone model in JSON for ...

Struggling to align images side by side using HTML and CSS along with figcaption and buttons

Adding buttons below images on my webpage is proving to be a bit challenging. I tried using the figcaption tag, but it resulted in the images stacking on top of each other instead of side by side. **My HTML:** <section class="mostpurch"> ...

Enable the ability to scroll and click to navigate an overlapping Div element

A customer has a website with a dark teal design and is not pleased with the appearance of the scroll bar, as it disrupts the overall style. The client requested that I find a solution without using third-party libraries, and one that they can easily under ...

Tips for transferring parameters between AJAX requests

Struggling to pass parameters between two different ajax calls, I've noticed that the params only exist within the ajax scope and not outside of it. Is there another way to achieve this without calling from one ajax success section to another ajax? He ...

Is there a way to switch between showing and hiding without my navigation menu expanding?

I am currently working on creating an index for a large list. However, I have encountered an issue where clicking on a letter to display its contents also pushes the other letters on the index bar (left nav) down. I want the other letters to stay collapsed ...