Solved

WaterMark Image with javascript

Posted on 2008-06-18
5
1,522 Views
Last Modified: 2012-06-21
Hi all,
I have web application developed by asp.net 2.0 (VS 2005), I have a page displaying a table with thefollowing information: Car Model ,Description and Image.
In the Database i stored image as a path. and i use a datalist control to display these information as a table.

Challenge:
When a car is sold, then i want to display a stamp such as [SOLD] to be displayed over the image.
i tried many ways, such as javascript [attahed code snippet]. but the problem is:
When i minimize the browser the [SOLD]  displayed in the same position that because position:absolute.

<ItemTemplate>
        <br />
        <table border="1" style="width: 100px; height: 100px">
         <tr>
         <td style="width: 100px">
        <asp:Image ID="Image1" runat="server" Height="94px" ImageUrl='<%# Eval("img") %>'
        Width="134px" />
       <script type="text/javascript" language="javascript">
       var top;
       var left;
      top=document.getElementById("DataList1_ctl00_Image1").style.top;
      left=450;
     document.write("<font color='red'><div id='d1' style='left:"+left+"px; width: 100px; position: absolute; top:"+top+"px; height: 100px;font-size:50px;font-color:red'>[SOLD]</div></font>")
          </script> 
     </td>
    </tr>
</table>
<br />
</ItemTemplate>

Open in new window

0
Comment
Question by:Mremawi
  • 3
5 Comments
 
LVL 10

Accepted Solution

by:
bluefezteam earned 200 total points
ID: 21811892
You should use CSS for this - i did it for a property site.

<div class="imageHolder"><img src="car.jpg"/><img src="sold.jpg" class="sold"/></div>

.imageHolder {
display:block;
width:200px;
height:100px;
position:relative;
}
.imageHolder .sold {
position:absolute;
bottom:0;
left:0;
}

This will then holder a sold sign at the base of the image so you can still see the item on sale/sold but there's a sold image over it.

in action or a variation of it can be seen here

http://www.jhilditch.com/buy.html
0
 
LVL 10

Expert Comment

by:bluefezteam
ID: 21811895
If possible can you move this item to CSS ? it is a CSS related issue.
0
 
LVL 1

Author Comment

by:Mremawi
ID: 21837141
Dear bluefezteam:

thank you very much for your solution, but can I make the image sold in middle of car.jpg image?
0
 
LVL 10

Expert Comment

by:bluefezteam
ID: 21840629
yes - instead of bottom:0; you just need to know the height of your JPEG and divide that by 2, then remove the height of the sold.jpg divided by 2.

Eg

the car graphic is 100px high - its mid point is 50px.
The sold image that sits on the top is 30px - its mid point is 15px.

this means to get sold.jpg to appear over the middle of the the car.jpg you pocition it from TOP or BOTTOM by 50-15 = 35px.

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question