Home > Web Front-end > H5 Tutorial > body text

How to implement left and right sliding toggle in jQuery

php中世界最好的语言
Release: 2018-03-27 16:41:15
Original
3630 people have browsed it

This time I will show you how to implement the left and right sliding toggle in jQuery. What are the precautions for jQuery to implement the left and right sliding toggle? The following is a practical case, let’s take a look.

We know that jQuery is used to move up and down, and you can directly use the slideUp() and slideDown() methods.

The slideUp() method and slideDown() method will only change the height of the element. If the

display attribute value of an element is "none", when the slideDown() method is called, the element will be displayed extending from top to bottom. The slideUp() method is just the opposite. The element will be shortened and hidden from top to bottom.

The code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>toggle-jquery1.9</title>
 <script src="https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js"></script>
 <style>
  p.container {
   height: 320px;
   border: 1px solid #ccc;
  }
  p.left {
   width: 200px;
   height: 300px;
   background-color: #36f;
  }
 </style>
</head>
<body>
 <p class="container">
  <p class="left"></p>
 </p>
 <button id="toggle">toggle</button>
 <script>
  $(document).ready(function(){
   $('#toggle').click(function(){
    $('.left').slideToggle(300);
   });
  });
 </script>
</body>
</html>
Copy after login

Then, to achieve left and right sliding What about sliding in and out?

The demo is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>toggle-jquery1.9</title>
 <script src="https://cdn.bootcss.com/jquery/1.9.0/jquery.min.js"></script>
 <style>
  p.container {
   height: 320px;
   border: 1px solid #ccc;
  }
  p.left {
   width: 200px;
   height: 300px;
   background-color: #36f;
  }
 </style>
</head>
<body>
 <p class="container">
  <p class="left"></p>
 </p>
 <button id="toggle">toggle</button>
 <script>
  $(document).ready(function(){
   $('#toggle').click(function(){
    $('.left').animate({width:'toggle'},350);
   });
  });
 </script>
</body>
</html>
Copy after login

The effect is as follows:

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to implement file upload with AjaxUpLoad.js

The order of operating Vue rendering and plug-in loading

The above is the detailed content of How to implement left and right sliding toggle in jQuery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!