Home > ASP.Net, Jquery > Enlarge Image on MouseOver in ASP.Net using JQuery

Enlarge Image on MouseOver in ASP.Net using JQuery


Hi all try this example to enlarge image on mouseover in asp.net using jquery


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Img_Enlarge.aspx.cs" Inherits="Img_Enlarge" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <title></title>
 <script type="text/javascript" src="Scripts/jquery-1.4.1.js"></script>
 <style type="text/css">
 .thumbnail
 {
 height: 100px;
 width: 100px;
 position: relative;
 }
 .image
 {
 position: relative;
 width: 400px;
 height: 250px;
 }
 </style>
 <script language="javascript" type="text/javascript">
 $(document).ready(function () {
 $(".thumbnail").mouseover(function () {
 $(".thumbnail").css("opacity", ".5");
 $(this).animate({ opacity: 1.0 });
 $("#imgContainer").append("<img class='image' src='" + $(this).attr("src") + "' />");

});
 $(".thumbnail").mouseout(function () {
 $(".thumbnail").css("opacity", "1.0");
 $(".image").remove();
 });
 });

 </script>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 </div>
 </form>
 <div align="center">
 <img class="thumbnail" src="Images/Tree.jpg" alt="" />
 <img class="thumbnail" src="Images/dock.jpg" alt="" />
 <img class="thumbnail" src="Images/forest.jpg" alt="" />
 <img class="thumbnail" src="Images/garden.jpg" alt="" />
 <div id="imgContainer">
 </div>
 </div>
</body>
</html>

If we want to apply it with Image from Database

In ASPX Page :-


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>AJAX Photo Gallery</title>
 <script src="jquery-1.1.4.js" type="text/javascript"></script>
 <style type="text/css">
 .thumbnail
 {
 height: 100px;
 width: 100px;
 position: relative;
 }
 .image
 {
 position: relative;
 width: 400px;
 height: 250px;
 }
 </style>
 <script language="javascript" type="text/javascript">
 $(document).ready(function () {
 $(".thumbnail").mouseover(function () {
 $(".thumbnail").css("opacity", ".5");
 $(this).animate({ opacity: 1.0 });
 $("#imgContainer").append("<img class='image' src='" + $(this).attr("src") + "' />");
 });
 $(".thumbnail").mouseout(function () {
 $(".thumbnail").css("opacity", "1.0");
 $(".image").remove();
 });
 });
 </script>
</head>
<body>
 <asp:Repeater ID="Repeater1" runat="server">
 <ItemTemplate>
 <img src='<%# Eval("ImagePath") %>' alt="" class="thumbnail" />
 </ItemTemplate>
 </asp:Repeater>
 <div id="imgContainer">
 </div>
</body>
</html>

and In code behind :-


protected void Page_Load(object sender, EventArgs e)
 {
 var list = (new[] { new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/1.jpg", Value = "1" } }).ToList();
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/2.jpg", Value = "2" });
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/3.jpg", Value = "3" });
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/4.jpg", Value = "4" });
 list.Add(new { ImagePath = "http://sandbox.scriptiny.com/slideshow/thumbs/5.jpg", Value = "5" });
 Repeater1.DataSource = list;
 Repeater1.DataBind();
 }

Hope this helps

Good Luck

 

Advertisements
Categories: ASP.Net, Jquery
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: