All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Curtain Opening Effect Using jQuery And CSS

Last Updated : Jul 1, 2023

IN - jQuery CSS | Written & Updated By - Amruta

In this tutorial we will show you how to create a curtain opening effect using jQuery and CSS.

You have seen in many shows and dramas the curtains on the stage moves to left and right side on show starting and then moves to right and left in ending that's exactly what we were going to create in this tutorial.

You may also like Parallax Effect On Scrolling Using jQuery And CSS.

Curtain Opening Effect Using jQuery And CSS

To Create Curtain Opening Effect It Takes Only Two Steps:-

  1. Make a HTML file and define markup and scripting
  2. Make a CSS file and define styling

Step 1. Make a HTML file and define markup and scripting

We make a HTML file and save it with a name effect.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="effect_style.css">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function open_curtain()
{
 $("#curtain1").animate({width:20},1000);
 $("#curtain2").animate({width:20},1000);
}
function close_curtain()
{
 $("#curtain1").animate({width:200},1000);
 $("#curtain2").animate({width:191},1000);
}
</script>
</head>
<body>
<div id="wrapper">

<div id="effect">
 <p>Surprise You Got A Lottery!</p>
 <img src="images/curtain1.jpg" id="curtain1">
 <img src="images/curtain2.jpg" id="curtain2">
</div>

<div id="curtain_buttons">
 <input type="button" value="OPEN CURTAIN" onclick="open_curtain();">
 <input type="button" value="CLOSE CURTAIN" onclick="close_curtain();">
</div>

</div>
</body>
</html>

In this step we create a 'effect' div and insert curtain images and then create two buttons to open and close the curtains.

In open_curtain() function we animate 1st curtain to left side and 2nd curtain to right side same as the real curtain opening effect.

In close_curtain() function we use just the opposite of previous function we animate 1st curtain to right and 2nd curtain to left.

You may also like Blink Text Effect Using CSS3.

Step 2. Make a CSS file and define styling

We make a CSS file and save it with a name effect_style.css

body
{
 text-align:center;
 width:100%;
 margin:0 auto;
 padding:0px;
 font-family:helvetica;
 background-color:#F79F81;
}
#wrapper
{
 text-align:center;
 margin:0 auto;
 padding:0px;
 width:995px;
}
#effect
{
 background-color:#610B0B;
 position:relative;	
 width:380px;
 height:220px;
 margin-left:300px;
 box-shadow:0px 0px 10px 0px #610B0B;
}
#effect p
{
 margin-top:10px;
 font-size:30px;
 color:#F79F81;
}
#curtain1
{
 top:0px;
 position:absolute;
 left:0px;
 height:220px;
}
#curtain2
{
 top:0px;
 position:absolute;
 height:220px;
 right:0px;
}
#curtain_buttons input[type="button"]
{
 margin-top:20px;
 width:150px;
 height:45px;
 border-radius:2px;
 color:white;
 background-color:#B43104;
 border:none;
 border-bottom:6px solid #8A2908;
}

Thats all, this is how to create curtain opening effect using jQuery and CSS. You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

I hope this tutorial on curtain animation css helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Amruta

Amruta is an Experienced web developer with 4 years for experience she completed her master's with MCA and passionate about programming Languages for creating technical contents like HTML, CSS, JavaScript, Java, Python, PHP, jQuery.

Follow Amruta On Linkedin 🡪