Drag-and-Drop By Michelle

Slides:



Advertisements
Similar presentations
CSS Cascading Style Sheets. Objectives Using Inline Styles Working with Selectors Using Embedded Styles Using an External Style Sheet Applying a Style.
Advertisements

Cascading Style Sheets
Chapter 3 – Designing your web pages Dr. Stephanos Mavromoustakos.
Advance CSS (Menu and Layout) Miftahul Huda. CSS Navigation MENU It's truly remarkable what can be achieved through CSS, especially with navigation menus.
1 Pengantar Teknologi Internet W03: CSS Cascading Style Sheets.
Recognizing the Benefits of Using CSS 1. The Evolution of CSS CSS was developed to standardize display information CSS was slow to be supported by browsers.
CSW131 Steven Battilana 1 CSW 131 – Chapter 5 (More) Advanced CSS Prepared by Prof. B. for use with Teach Yourself Visually Web Design by Ron Huddleston,
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
4.01 Cascading Style Sheets
Using color and fonts in HTML and XHTML Please use speaker notes for additional information!
CSS (Cascading Style Sheets): How the web is styled Create Rules that specify how the content of an HTML Element should appear. CSS controls how your web.
Advanced CSS - Page Layout. Advanced CSS  Compound Selectors:  Is a Dreamweaver term, not a CSS term.  Describes more advanced types of selectors such.
ITP 104.  While you can do things like this:  Better to use styles instead:
CSS Netcentric. What is CSS O CSS stands for Cascading Style Sheets O Styles define how to display HTML elements O Styles were added to HTML 4.0 to solve.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Web Programming Language CSS – Part 2 Dr. Ken Cosh (CSS II)
WRA HTML & CSS – BUILDING WEBPAGES. TODAY’S AGENDA Review: external stylesheets Review: transforming a list Intro: the object Intro: the.
Cascading Style Sheets (CSS) EXPLORING COMPUTER SCIENCE – LESSON 3-5.
CIS67 Foundations for Creating Web Pages Professor Al Fichera Rev. September 22, 2010—All HTML code brought to XHTML standards. Reference for CIS127 and.
CSS IS A LANGUAGE DESIGNED TO TARGET HTML ELEMENTS AND NODES BY TYPE, CLASS, ID AND VALUE, AND CHANGE THEIR VALUES CSS – change how your HTML looks and.
Group 9: Through examples, explain how to build a css navigation bar. Presented by: Daniel Ku, Matt Iannacci & Iphia Henry.
HTML & CSS Contents: the different ways we can use to apply CSS to The HTML documents CSS Colors and Background CSS Fonts CSS Text CSS box model: padding,
>> CSS Layouts. Recall Properties of Box – Border (style, width, color) – Padding – Margin – Display – Background – Dimension Welcome Padding Area Border.
Tutorial 4 Using CSS for Page Layout. Objectives Session 4.1 – Explore CSS layout – Compare types of floating layouts – Examine code for CSS layouts –
WebD Introduction to CSS By Manik Rastogi.
CSS.
Working with Cascading Style Sheets
Cascading Style Sheets (CSS)
Cascading Style Sheet.
Introduction to CSS Layout
Chapter 4: Feature Detection & Drag and Drop
Internal Style Sheets External Style Sheets
The Box Model in CSS Web Design – Sec 4-8
4.01 Cascading Style Sheets
Cascading Style Sheet.
CSS Layouts: Positioning and Navbars
CSS Layouts: Grouping Elements
Unit 3 - Review.
Lab Styling Tabs with CSS Scott Lydiard
Creating Your Book Review Web Site
Introduction to Web programming
Cascading Style Sheets (Layout)
The Box Model in CSS Web Design – Sec 4-8
>> CSS Layouts.
IS333: MULTI-TIER APPLICATION DEVELOPMENT
CSS Cascading Style Sheets
Website Design 3
TOPICS Chrome Dev Tools Process for Building a Static Website
MORE Cascading Style Sheets (The Positioning Model)
Software Engineering for Internet Applications
Web Programming Language
Grids, Floats & Flex Boxes
Working with Cascading Style Sheets (CSS)
Working with Cascading Style Sheets (CSS)
What are Cascading Stylesheets (CSS)?
Book / movie report Web design.
HTML and CSS MIS 2402 Jeremy Shafer Department of MIS
Drag-and-Drop Processing
Training & Development
Web Design and Development
Exercise 9 Skills You create and use styles to create formatting rules that can easily by applied to other pages in the Web site. You can create internal.
Web Programming Language
4.01 Cascading Style Sheets
Cascading Style Sheets III B. Com (Paper - VI) & III B
Introduction to Cascading Style Sheets (CSS)
Introduction to Styling
Internal Style Sheets External Style Sheets
CSS Classes.
Presentation transcript:

Drag-and-Drop By Michelle What: I’ve created a webpage with a sentence completion activity using drag-and-drop. My webpage has two possible answers that can be dragged down to a blank space that is primed to receive them.

Drag-and-Drop To do: a very brief outline CSS HTML JavaScript Make IDs that can be used to create divs. Make a destination div. Give it event handlers linked to functions that will allow a drop. Make answer divs. Make them draggable, then give each one an event handler and a function for doing the drag. Make a function that will let the user pick up an element (here, the user will pick up an answer div). Make a function that will allow the element to cross into the destination div’s territory without activating default settings that will prevent the drop (here, the destination is a blank space/box). Make a function that will allow the user to drop the answer div onto the destination div.

The Important Code CSS a. The divs will become boxes. HTML #answer1{display:inline; font-family:Arial; font-size:50px; height:50px; width:75px; background-color:white;} #blank{float:left; padding-left:10px; padding-right:5px; padding-top:10px; margin-top:140px; margin-left:5px; margin-right:5px; height:100px; width:120px; background-color:white; border-bottom:thin solid black;} HTML b. The destination div needs handlers and functions. c. The answer divs need to be draggable. They also need a handler and function.  <div id="blank" ondrop="drop(event)" ondragover="allowCrossOver(event)"> <div id="answer1" draggable="true" ondragstart="drag(event)">   JavaScript d. drag()   e. allowCrossOver()  f. drop() function drag(abstractBundle) //W3S {abstractBundle.dataTransfer.setData("Text",abstractBundle.target.id);}   function allowCrossOver(abstractBundle) //W3S {abstractBundle.preventDefault();} function drop(abstractBundle) //W3S {abstractBundle.preventDefault(); var data=abstractBundle.dataTransfer.getData("Text"); abstractBundle.target.appendChild(document.getElementById(data));}

Set-up: Put the following code in an HTML document: <!DOCTYPE html> <html lang="en"> <head> <title>Drag and Drop Example</title> <meta charset="utf-8"> </head> <body> <p class="directions">Complete the sentence by dragging the answer to the blank space. </p> <br> <div class="center"> <div id="answer1" draggable="true" ondragstart="drag(event)">are</div> <!-- Attribution: I am using w3dragdrop.html's code for setting up the properties and connecting the event handlers to the correct elements -->   <div id="answer2" draggable="true" ondragstart="drag(event)">will</div> <!-- Attribution: see above --> </div> <p class="sentence">On Tuesday, we </p> <div id="blank" ondrop="drop(event)" ondragover="allowCrossOver(event)"></div> <p class="sentence"> going to the beach.</p> <!-- Attribution: see above --> </body> </html>

Set-up: Put the following code in a CSS file ( Set-up: Put the following code in a CSS file (.css) or within <style></style> tags in the head of the HTML document: #answer1{display:inline; font-family:Arial; font-size:50px; height:50px; width:75px; background-color:white;} #answer2{display:inline; #blank{ float:left; padding-left:10px; padding-right:5px; padding-top:10px; margin-top:140px; margin-left:5px; margin-right:5px; height:100px; width:120px; background-color:white; border-bottom:thin solid black;} .sentence{float:left; padding-top:100px; display:inline;} .directions{font-size:60px; font-family: Arial;} body{background-color:#ccffcc;} .center{margin:auto; width:55%;}

Set-up: Put the following code in a JavaScript file ( Set-up: Put the following code in a JavaScript file (.js) or within <script></script> tags in the head of the HTML document: function drag(abstractBundle) //Attribution: function code from W3 Schools { abstractBundle.dataTransfer.setData("Text",abstractBundle.target.id); } function allowCrossOver(abstractBundle) //Attribution: function code from W3 Schools abstractBundle.preventDefault(); function drop(abstractBundle) //Attribution: function code from W3 Schools var data=abstractBundle.dataTransfer.getData("Text"); abstractBundle.target.appendChild(document.getElementById(data));

Let’s start by using CSS to style the webpage Let’s start by using CSS to style the webpage. I want my blank box to go in between two parts of my sentence, so the sentence class needs to display inline. Below is a screenshot of the webpage. *The screenshot also includes the related HTML. We’ll look at that later. .sentence{float:left; .directions{font-size:60px; padding-top:100px; font-family: Arial;} font-family:Arial; font-size:50px; body{background-color:#ccffcc;} display:inline;} .center{margin:auto; width:55%;}

I’m using divs to hold my answers and make my blank space I’m using divs to hold my answers and make my blank space. My divs are going to be boxes, so they each need a height, a weight, and a background-color. #answer1{display:inline; #answer2{display:inline; #blank{float:left; height:100px; font-family:Arial; padding-left:10px; width:120px; font-size:50px; padding-right:5px; background-color:white; height:50px; padding-top:10px; border-bottom:thin solid width:75px; margin-top:140px; black;} background-color:white;} margin-left:5px; margin-right:5px;

Let’s move on to the HTML. The code for the directions is first Let’s move on to the HTML. The code for the directions is first. And easy. HTML Code: <p class="directions">Complete the sentence by dragging the answer to the blank space. </p> Explanation: We already gave the directions the style we wanted in CSS. Now we can just apply them, using class=“directions.”

Now, take a look at the answer divs Now, take a look at the answer divs. *I’m using W3 School’s Drag and Drop Tutorial’s example for the code for the draggable attribute, the event handlers, and the functions. I’ve noted which lines are from this tutorial in the comments of the code itself using <!--W3S->. Explanation: Make the answer divs, including the appropriate CSS IDs. Within the opening tag (after the ID), make each div draggable, add the event handler ondragstart and then connect this handler to the function drag(). The function should have an argument - the argument is called event. Put the text for each answer between the opening and closing div tags. Center the two divs by putting them in another div that uses the class “center.” HTML Code: <div class="center"> <div id="answer1" draggable="true" ondragstart="drag(event)">are</div> <!—W3S ->   <div id="answer2" draggable="true" ondragstart="drag(event)">will</div> <!—W3S -> </div>

Finally, we make the sentence and the blank. Explanation: This is the first half of the sentence. Remember from the CSS that the class .sentence displays inline and floats left. The id #blank makes a box that also floats left (so it lies against the text). It has an event handler called ondragover that waits for an element to get dragged into its borders. When this action happens, it records data about the event, and sends that data on to the function allowCrossOver(). The tag for this box also has a handler that waits for the user to drop an element onto it. The handler passes the data it collects to the function drop(). Now, we finish our sentence. The class .sentence keeps the second half of the sentence on the same line. HTML Code: <p class="sentence">On Tuesday, we </p> <div id="blank" ondrop="drop(event)" ondragover="allowCrossOver(event)"></div> <!—W3S -> <p class="sentence"> going to the beach.</p>

Our JavaScript starts with the function drag() Our JavaScript starts with the function drag(). *I’m using functions from W3 School’s tutorial. Explanation: The function drag() allows a user to pick up an element. Before the function can work, the element needs an event handler in its HTML tag. This handler creates data about the event and the element. We need to store or set this data. In the screenshot above, the user has selected “are.” The function drag() is storing information about the user’s action; this stored information helps the later functions know which element to “worry about.” JavaScript Code: function drag(abstractBundle) { abstractBundle.dataTransfer.setData("Text",abstractBundle.target.id); }

Our second function is allowCrossOver() Our second function is allowCrossOver() *I’m using W3 School’s functions. Explanation: We want to move our element across boundaries. Default settings don’t let users do this. We can override these settings by putting the preventDefault() method inside our allowCrossOver() function. JavaScript Code: function allowCrossOver(abstractBundle) //Attribution: function code from W3 Schools { abstractBundle.preventDefault(); }

Our final function is drop() *I am using W3 School’s functions Explanation: To let the user drop an element, we once again need to override default settings. We need to get and store information from the parameter abstractBundle. We use the method getData() to obtain the information and then we create a variable called data to hold the information. We can use the information carried in the variable data to recreate our element using appendChild(), this time in our destination. JavaScript Code: function drop(abstractBundle) { abstractBundle.preventDefault(); var data=abstractBundle.dataTransfer.getData("Text"); abstractBundle.target.appendChild(document.getElementById(data)); }

Importance When I organize information, I like to use note-cards. I can group them in different ways, and when I use them, I feel more creative than when I’m simply writing things on paper or typing using word-processing software. Likewise, I find drag-and-drop software and websites more fun to use than ones that are more linear. It is much easier for a user to select or even sort options by dragging and dropping instead of typing into forms. This technique also makes it easier to visualize what one has selected, and notice errors. In addition, many new laptops have a touchscreen option. While traditional forms aren’t very well suited to touchscreen technology, touchscreens are made for drag-and-drop selection. Clearly companies are making touchscreens because they believe that drag-and-drop technology is what the market wants; this certainly seems to be true in the case of smart phones. As more customers get devices with touchscreens, web developers will need to create drag-and-drop websites. I didn’t have an easy time creating CSS and HTML that worked well with drag- and-drop JavaScript functions. For my webpage to be coherent, I needed to place my #blank div very carefully. As difficult as it was to work out those details, I’m glad I have a basic understanding of drag-and-drop technology: likely it will be a big part of web development in the future.

Resources Ballard, Phil and Michael Moncur. Sams Teach Yourself JavaScript in 24 Hours 5th ed. Indiana: Sams, 2013. Print. Blum, Ken and Lee Cottrell. HTML5 Multimedia Developer’s Guide. McGraw Hill, 2012. Print. “HTML5 Drag and Drop.” W3 Schools.com. Web. Access date: 5 May 2014.