All TalkersCode Topics

Follow TalkersCode On Social Media

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

Slide Text On Images Using jQuery

Last Updated : Jul 1, 2023

IN - CSS jQuery | Written & Updated By - Pragati

In this tutorial we will show you how to slide text on images using jQuery and CSS.It looks nice and also saves space for more writing, whenever user hover on image a text appear from bottom to top with sliding effect.

You may also like display text over image using HTML and CSS.

Slide Text On Images Using jQuery

To Slide Text On Image 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 slide.html

<html>
<head>
 <link href="slide.css"  rel="stylesheet" type="text/css"/>
 <script type="text/javascript" src="js/jquery.js"></script>
 <script>
  $(document).ready(function() 
  {
   $('.text_conainer').hover(function()
   {
    $('.text_div').slideToggle('slow');
   },
   function()
   {
    $('.text_div').slideToggle('slow');
   });
  });
 </script>

</head>
<body>
<div id="wrapper">
 <div class="text_conainer">
  <img src="image1.jpg"/>
  <div class="text_div">
   <h2>TalkersCode.com</h2>
   <p>Demo Of Sliding Text On Image</p>
  </div>
 </div>
</div>
</body>
</html>

In this step we create a div to hold image and text and we use jQuery slideToggle() function to slide the text up and down on hover. You may also like add text on image using PHP.

Step 2. Make a CSS file and define styling

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

body
{
 text-align:center;
 width:100%;
 margin:0 auto;
 padding:0px;
 font-family:helvetica;
 background-color:#086A87;
}
#wrapper
{
 text-align:center;
 margin:0 auto;
 padding:0px;
 width:995px;
}
.text_conainer 
{
 width:400px;
 height:300px;
 position: relative;
 margin: 5px;
 margin-left:300px;
 color: #333;
}
.text_conainer img
{
 height:300px;
 width:400px;
}
.text_conainer .text_div 
{
 display: none;
 opacity: 0.8;
 background:#58ACFA;
 width: 400px;
 position: absolute;
 bottom: 0px;
 padding: 5px;
 box-sizing:border-box;
 text-align:center;
 color:white;
}

In this step we make our 'text_conainer' relative and 'text_div' absolute remember this without using these positions the text will never slide over image.

You may also like add watermark on image using PHP.

Thats all, this is how to slide text on images using jQuery. 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 slide text on images using jQuery helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Pragati

Experienced coding content writer who enjoys breaking down complex concepts in programming languages like Java, Python, C, and C++. Over three years of experience producing interesting and relevant content for a variety of entities. Committed to providing concise and easy-to-understand articles that assist readers in easily understanding technology and industry trends in the world of coding and software development.

Follow Pragati On Linkedin 🡪