You are here:   Home
Register   |  Login

Captured Technology - Blog

Minimize

Creating Image Buttons that Resize on Mouse Over

Jun 9

Written by:
6/9/2009 12:33 PM  RssIcon

Creating Image Buttons that Resize on Mouse Over

We needed to have a different way than previously designed to have image buttons enlarge on hover over that included a text label. So I wrote the code below to fill a table cell with an image and change the image onmouseover. The trick was getting the label to sit right on top on the images and having the images swap correctly. I used a div area to push the label down to the right spot on the image. And then I used some css style attributes in JavaScript to get the image to change when needed.

First the Markup Page:

<table cellpadding="0" cellspacing="0" width="226">
<tr>    
    <td align="center" valign="bottom" width="226" height="101" 
        style="background-image: iamamemberofthemedia.png; background-repeat: no-repeat;" 
        id="tdImage" runat="server" >
        <asp:LinkButton ID="btnHeader" runat="server" Height="91" Width="204" CssClass="image_overlay">
        asp:LinkButton>
        <div style="height:4px; cursor:hand;"> div>
    td>    
tr>
table>

The Code Behind:

    Private _NavigateURL As String = String.Empty
    Public Property NavigateURL() As String
        Get
            Return Me._NavigateURL
        End Get
        Set(ByVal value As String)
            Me._NavigateURL = value
        End Set
    End Property

    Public Property HeaderText() As String
        Get
            Return Me.btnHeader.Text.Replace("
"
, "") End Get Set(ByVal value As String) Me.btnHeader.Text = "
"
& value End Set End Property Public Property ImageURL() As String Get Return Me.tdImage.Attributes.CssStyle.Item("background-image") End Get Set(ByVal value As String) Me.tdImage.Attributes.CssStyle.Clear() Me.tdImage.Attributes.CssStyle.Add("background-image", ResolveUrl(value)) Me.tdImage.Attributes.CssStyle.Add("background-repeat", "no-repeat") Me.tdImage.Attributes.CssStyle.Add("background-position", "center center") Me.tdImage.Attributes.Add("onmouseout", "this.style.backgroundImage='url(" & ResolveUrl(value) & ")'; this.style.backgroundRepeat='no-repeat'; this.style.backgroundPosition='center center'") End Set End Property Public WriteOnly Property HoverImageURL() As String Set(ByVal value As String) Me.tdImage.Attributes.Add("onmouseover", "this.style.backgroundImage='url(" & ResolveUrl(value) & ")'; this.style.backgroundRepeat='no-repeat'; this.style.backgroundPosition='center center'") End Set End Property Public Sub Navigate() Response.Redirect(Me.NavigateURL) End Sub Protected Sub btnHeader_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHeader.Click Me.Navigate() End Sub

Tags:
Categories:

1 comment(s) so far...


Gravatar

Re: Creating Image Buttons that Resize on Mouse Over

You need to be careful when resizing images that it doesn't have an adverse effect on page layout. People should always bear this in mind when doing any kinda resizing...

By paul on   6/10/2009 7:20 AM

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
CAPTCHA image
Enter the code shown above in the box below
Add Comment   Cancel 

FaceBook

Minimize

Mobile Version

Minimize
Add CapturedTech - Technology Mippin widget

Translate

Minimize

Sponsors

Minimize
Call Now: 877-672-3078

Recent Comments

Minimize
Re: Three Benefits to Using a Royalty-Free Image on Your Website or Blog
I also prefer to use royalty-free images. They give more credibility in your site or blog posts.
Re: Websites vs. Facebook Pages (Infographic)
Internet can be very useful for small business to market them self, there is always some free way to reach your audience via Internet.
Re: Is Keyword Density Still Important For On Page SEO
The search engines hadn’t quite caught up yet. As a result, it wasn’t uncommon to see sites rank highly when their content read something like this.that they follow SEO best practices than you will by trying to figure out a way to get your keywords into your page content another one or two times.
Re: Websites vs. Facebook Pages (Infographic)
Very interesting topic, infographics was a new concept for me, will definitely use it.
Re: Reducing Small Business Blues
Running a business is tough and you are right, most of the time you are the core aspect of each area of a business. I don't think I could handle doing my own accounting, like you I am too terrible with numbers!

u comment, i follow