I am using MVC2 in my project.I have this code in the ".aspx" page which determines if the ".ascx" page should be displayed:
<% if(Model.MRxECG != null) { %>
<div id="ecg">
<% Html.RenderPartial("ecgDetails", Model); %>
</div>
<% } %>
This is the code in ".ascx" page.
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Intranet.Models.CareRecord.CareRecordSummaryModel>" %>
<script type="text/javascript">
function resImage(image)
{
var resize = 200; // amount in percentage
var oldheight = 150; // height of your image
var oldwidth = 250; // width of your image
var X = event.x;
var Y = event.y;
var newHeight = oldheight * (resize / 100);
var newWidth = oldwidth * (resize / 100);
image.style.height = newHeight;//height of new image
image.style.width = newWidth;// width of new image
var c = image.parentNode;
c.scrollLeft = (X * (resize / 100)) - (newWidth / 2) / 2; //this is for
c.scrollTop = (Y * (resize / 100)) - (newHeight / 2) / 2;//new center
}
</script>
<div>
<table class="layout" width="900px">
<tr>
<td>
<img src='<%= Url.Action("ShowMRx12LeadImage", "CareRecord", new { id = Model.CareRecord.CaseNumber}) %>'
alt="12-Lead ECG" style="width: 1000px; height: 800px;" onmouseover="resImage(this)" />
</td>
</tr>
</table>
</div>
The image doesn't zoom on mouseover event. I tried placing the Javascript code in the ".aspx" page but thata didnt work. What should I do to make this work?
I am not sure if Javascript works in the .ascx page.Do I have to ue jQuery to achieve the zoom-in functionality?
The image.style.height
should be a string with specified dimension (px), not a number.
Consider changing these lines:
image.style.height = newHeight + 'px';//height of new image
image.style.width = newWidth + 'px';// width of new image
There is a sample of onmouseover
: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseover , you can try here how it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.