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
Advertisement