Mouse-over Effects. Text based buttons

Similar documents
Using Dreamweaver CC. 6 Styles in Websites. Exercise 1 Linked Styles vs Embedded Styles

Using Dreamweaver CS6

Lesson 5 Introduction to Cascading Style Sheets

DAY 4. Coding External Style Sheets

Using Dreamweaver. 6 Styles in Websites. 1. Linked or Imported Stylesheets. 2. Embedded Styles. 3. Inline Styles

CS Multimedia and Communications REMEMBER TO BRING YOUR MEMORY STICK TO EVERY LAB!

Lab 4 CSS CISC1600, Spring 2012

Cascading Style Sheets (CSS)

Fundamentals of Web Technologies. Agenda: HTML Links 5/22/2017. HTML Links - Hyperlinks HTML Lists

CSS cont. October 5, Unit 4

Introduction to Computer Science Web Development

Introduction to using HTML to design webpages

Introduction to HTML Tables & Linking CSS files (A, B, C) COGS3 Introduction to Computing Assignment

GIMP WEB 2.0 MENUS WEB 2.0 MENUS: HORIZONTAL NAVIGATION BAR CREATING AN HTML LIST

INTRODUCTION TO JAVASCRIPT

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Css Manually Highlight Current Link Nav Link

Cascading Style Sheet. Styles as Tag Attributes. Syntax. <h1>: what font type/size is used? STYLE = SELECTOR {RULES} Attributes such as bgcolor

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar with Dynamic Background Image

Teach Yourself HTML5 & CSS 3: Week 5 Task 13 - Anchors Part 3

Lesson 1 using Dreamweaver CS3. To get started on your web page select the link below and copy (Save Picture As) the images to your image folder.

The default style for an unordered (bulleted) list is the bullet, or dot. You can change the style to either a square or a circle as follows:

(try adding using css to add some space between the bottom of the art div and the reset button, this can be done using Margins)

<body bgcolor=" " fgcolor=" " link=" " vlink=" " alink=" "> These body attributes have now been deprecated, and should not be used in XHTML.

CSS worksheet. JMC 105 Drake University

Lesson 5: Introduction to Events

CSS means Cascading Style Sheets. It is used to style HTML documents.

Microsoft Expression Web Quickstart Guide

Class 3 Page 1. Using DW tools to learn CSS. Intro to Web Design using Dreamweaver (VBUS 010) Instructor: Robert Lee

Creating and Building Websites

Siteforce Pilot: Best Practices

Using Dreamweaver CS6

Want to add cool effects like rollovers and pop-up windows?

Place User-Defined Functions in the HEAD Section

ENGL 323: Writing for New Media Repurposing Content for the Web Part Two

Dreamweaver: Web Forms

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Unit 10 - Client Side Customisation of Web Pages. Week 5 Lesson 1 CSS - Selectors

Dreamweaver Basics. Planning your website Organize site structure Plan site design & navigation Gather your assets

Adobe Dreamweaver CC Tutorial

Setting a Background Image

Web standards and IE8

HTML, beyond the basics

GIMP WEB 2.0 MENUS. Web 2.0 Menus: Horizontal Navigation Bar

Classic Apps Editor Best Practices

7300 Warden Avenue, Suite 503 Markham, Ontario Canada L3R 9Z6. Phone: Toll Free: Fax:


LECTURE-3. Exceptions JS Events. CS3101: Programming Languages: Javascript Ramana Isukapalli

Lecture B3 Style : Algorithmic Thinking. Computing and Art : Nature, Power, and Limits CC 3.12: Fall 2007

Web Development & Design Foundations with HTML5, 8 th Edition Instructor Materials Chapter 14 Test Bank

Beginning HTML. A tag is a command written between angle brackets (the less than and greater than symbols). Ex. <html>

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

Schoolwires Editor Best Practices. Schoolwires Centricity2

Creating a Navigation Bar with a Rollover Effect

Overview of the Adobe Dreamweaver CS5 workspace

Lesson 1 HTML Basics. The Creative Computer Lab. creativecomputerlab.com

Dynamic documents with JavaScript

Session 4. Style Sheets (CSS) Reading & References. A reference containing tables of CSS properties

Head First HTML 5 Programming: Chapter 3: Events, Handlers, and all that Jazz.

JavaScript Objects. John M. Morrison. May 10, Case Study: Introducing BallWorld 5. 4 Making Balls Appear in the Canvas 9

jquery Tutorial for Beginners: Nothing But the Goods

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Head First HTLM 5 Programming, Chapter 1: Welcome to Webville. Pages 1-34

CSS Selectors. element selectors. .class selectors. #id selectors

Web Recruitment Module Customisation

1. Setup a root folder for the website 2. Create a wireframe 3. Add content 4. Create hyperlinks between pages and to external websites

HTML, CSS. Kristóf Kovács, Róbert Pálovics, Ferenc Wettl Kristóf Kovács, Róbert Pálovics, Ferenc Wettl HTML, CSS / 28

There are two main types of buttons: Example: These generally fall into two camps: Example:

CSS: formatting webpages

CSS Styles Quick Reference Guide

Name Ella Swain Assessment Number. East St Cafe. Project Name ORGANISING AND PLANNING

Fundamentals of Website Development

5 Snowdonia. 94 Web Applications with C#.ASP

Photo from DOM

ORB Education Quality Teaching Resources

Time series in html Canvas

Web Design and Application Development

Before you begin, make sure you have the images for these exercises saved in the location where you intend to create the Nuklear Family Website.

Using echoice Affiliate Tools

FrontPage Help Center. Topic: FrontPage Basics

c122jan2714.notebook January 27, 2014

CREATING A BUTTON IN PHOTOSHOP

Introduction, Notepad++, File Structure, 9 Tags, Hyperlinks 1

HIGHER. Computing Science. Web Design & Development Implementation Tasks. Ver 8.9

Project 1: Using Cascading Style Sheets to Make Selectable Themes

HTML and CSS a further introduction

CSS. Selectors & Measurments. Copyright DevelopIntelligence LLC

Programing for Digital Media EE1707. Lecture 4 JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

Proper_Name Final Exam December 21, 2005 CS-081/Vickery Page 1 of 4

KillTest *KIJGT 3WCNKV[ $GVVGT 5GTXKEG Q&A NZZV ]]] QORRZKYZ IUS =K ULLKX LXKK [VJGZK YKX\OIK LUX UTK _KGX

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

Improved Web Development using HTML-Kit

PROFILE DESIGN TUTORIAL KIT

Unit 5 Web Publishing Systems Page 1 of 13 Part 4 HTML Part 4

NAVIGATION INSTRUCTIONS

CSS: Formatting Text. CSS for text processing: font-family. Robert A. Fulkerson

INFO 2450 Project 6 Web Site Resources and JavaScript Behaviors

3. Each of these mark examples contains an error. a. <input name= country value= Your country here. /> b. <checkbox name= color value= teal />

JavaScript. Like PHP, JavaScript is a modern programming language that is derived from the syntax at C.

Web Site Design. Stanford University Continuing Studies CS 03. Mark Branom

Transcription:

Mouse-over Effects Text based buttons

Mouse-over Effects: Text based buttons. The purpose of this pamphlet is to give you a simple and quick example that illustrates the use of text based mouse-over effects in your web pages. To do this, we are going to show two simple examples of a text based button. This button will change colors when you hover your mouse over it and will return to its original color when you move your mouse away from the button. The button will also change colors when you click on it. To achieve this effect we will use HTML, JavaScript and CSS. If you are not familiar with these, don't worry. This will be a very simple example. You will only need to use a text editor like notepad or gedit and a modern browser that has JavaScript enabled. Lets start with the HTML part. Open your favorite text editor and type in the following: <html> <head> <title>example of a Text Button</title> </head> <body> </html> </body> Save your document as button.html and then use your browser to open it. You should see a blank page with Example of a Text Button at the top. Go back to your editor and type the following after the <title> tags.

<title>example of a Text Button</title> <style type="text/css">.normalbutton { </style> </title> This will establish the initial look of our button using a CSS class that we called normalbutton. In our HTML we can apply this class to a <span> tag to create the look of our text. Between your body tags type the span tags and text shown below: <body> <span id='mybutton1' class='normalbutton'>go to McNeal Data</span> </body> After you finish typing the text above, save the file again. If you were to refresh your browser you would probably see something like this:

Now we have a nice text based button but if you were to click on it, nothing would happen. Thats because we have not entered any JavaScript behind the code. To invoke JavaScript we are going to user script tags after the style tags. We will only need a single function to achieve a mouse-over effect. <script type= text/javascript > function changebuttoncolor(buttonname, buttoncolor, backgroundcolor) { var thebutton = document.getelementbyid(buttonname); thebutton.style.backgroundcolor = backgroundcolor; thebutton.style.color = buttoncolor; </script> This function will allow us to pass the name of the button, the color we want the button to be and its background color to a couple of commands within the function. These commands will change the style of the button to reflect the new colors we want it to be. The first line of the function... var thebutton = document.getelementbyid(buttonname); initializes a variable called thebutton. This variable will hold the location of the object we want to change. In this case an object can be just about any HTML object on the web page, but in our case it is going to be our <span> tag. We get the reference to the object by using the document.getelementbyid command. If you remember our span tag we gave it a name of mybutton1. <span id='mybutton1' class='normalbutton'>go to McNeal Data</span> We will pass this name to the function so it will know that this is what we want to change colors. So the span id and the buttonname will point to each other. var thebutton = document.getelementbyid('mybutton1'); <span id='mybutton1'... The other two commands will change the foreground color...

thebutton.style.color = buttoncolor; and the background color... thebutton.style.backgroundcolor = backgroundcolor; depending on what you assign buttoncolor and backgroundcolor variables to be. Now you will notice that when you type this formula in your code and refresh your browser, nothing happens when you click on the button. That is because we have not put in a trigger that tells the browser to execute the function. The triggers that we will use in this example are the onmouseover, onmouseout and onmousedown events. To use them we have to add them to the span. Lets start by adding the onmouseover event to our span. We are going to add the following to our span... onmouseover= changebuttoncolor('mybutton1', 'blue', 'white') So our span will now look like this... <span id='mybutton1' class='normalbutton' onmouseover= changebuttoncolor('mybutton1', 'blue', 'white') >Go to McNeal Data</span> If you were to refresh your browser at this point and hover your mouse cursor over it you would see the that the button now has a white background and the text has turned blue.

If you move your mouse cursor away from the button it stays the same color. To make it return to its original color we need to use the onmouseout event. We can now add the following to our span... onmouseout = changebuttoncolor('mybutton1', 'black', 'silver') Our span code will now look like this... <span id='mybutton1' class='normalbutton' onmouseover="changebuttoncolor('mybutton1','blue','white')" onmouseout="changebuttoncolor('mybutton1','black','silver')"> Go to McNeal Data </span> To make the button actually do some work we need to tell our web page to do something when the mouse button is pressed. We can use the onmousedown event to to this. We will need a new function to define what kind of work we want performed. In this case we will use the window.location command to tell the browser to go to the McNeal Data home page. After the changebuttoncolor function we will add a new function called gotomainsite(). function gotomainsite() { window.location= http://www.mcnealdata.com ; Then in our span we will add the onmousedown event like this... onmousedown = gotomainsite() So the whole span will look like this... <span id='mybutton1' class='normalbutton' onmouseover="changebuttoncolor('mybutton1','blue','white')" onmouseout="changebuttoncolor('mybutton1','black','silver')" onmousedown="gotomainsite()"> Go to McNeal Data </span> Now when you click the button it will go to the McNeal Data site. The whole web page source code should look like the listing shown below:

<html> <head> <title>example of a Text Button</title> <style type="text/css">.normalbutton { </style> <script type="text/javascript"> function changebuttoncolor(buttonname, buttoncolor, backgroundcolor) { var thebutton = document.getelementbyid(buttonname); thebutton.style.backgroundcolor = backgroundcolor; thebutton.style.color = buttoncolor; function gotomainsite() { window.location="http://www.mcnealdata.com"; </script> </head> <body> <span id='mybutton1' class='normalbutton' onmouseover="changebuttoncolor('mybutton1','blue','white')" onmouseout="changebuttoncolor('mybutton1','black','silver')" onmousedown="gotomainsite()"> Go to McNeal Data </span> </body> </html> You can also just use just CSS to produce this effect. Again you would start out by creating a blank HTML file in your favorite text editor this time called button2.html <html> <head> <title>example of a Text Button using CSS only</title> </head> <body> </body> </html> Our CSS will take advantage of the four possible states of a hyperlink tag: link, visited, hover and active. In the link state the hyperlink text has not been used. The visited state is the look of the hyperlink after is has been used. The hover state is what the hyperlink text looks like when the mouse

cursor is hovering over it. The active state can be used to change the appearance of the hyperlink when it is clicked. After the title tags add your script tags and the associated text as shown below: <style type="text/css">.button a:link {.button a:visited {.button a:hover { color:blue; background-color:white;.button a:active { </style> Next enter the following between the body tags: <div class="button"> <a href="http://www.mcnealdata.com">go to McNeal Data</a> </div> The whole web page should look like the following:

<html> <head> <style type="text/css">.button a:link {.button a:visited {.button a:hover { color:blue; background-color:white;.button a:active { </style> </head> <body> <div class="button"> <a href="http://www.mcnealdata.com">go to McNeal Data</a> </div> </body> </html> Save your file and then open it in your favorite browser. You should see a page like this:

If you hover your mouse over the button, it should change colors and if you click on it, it will take you to the McNeal Data web site. You can download this from the McNeal Data website at http://www.mcnealdata.com. You can also view a video tutorial there as well. Feel free to play with this code and use different colors in for your buttons or to add more buttons if you like.