![Phân tích tư tưởng của nhân dân qua đoạn thơ: Những người vợ nhớ chồng… Những cuộc đời đã hóa sông núi ta trong Đất nước của Nguyễn Khoa Điềm](https://timtailieu.net/upload/document/136415/phan-tich-tu-tuong-cua-nhan-dan-qua-doan-tho-039-039-nhung-nguoi-vo-nho-chong-nhung-cuoc-doi-da-hoa-song-nui-ta-039-039-trong-dat-nuoc-cua-nguyen-khoa-136415.jpg)
giáo trình HTML5 và CSS3 từng bước phần 8
Số trang: 26
Loại file: pdf
Dung lượng: 1.33 MB
Lượt xem: 12
Lượt tải: 0
Xem trước 3 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tham khảo tài liệu giáo trình html5 và css3 từng bước phần 8, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
giáo trình HTML5 và CSS3 từng bước phần 8 307 Using the HTML5 TagThis example adds a .click() function thanks to jQuery . The .click() function examineswhere the mouse click occurred within the canvas element . It then clears the canvas anddraws a new rectangle at the point where the mouse was clicked . This example begins toshow the interactivity that’s possible with the canvas element .Finally, here’s the fun example that I promised . Building on the previous example, thecode shown here creates a larger canvas on a page, and then builds a number of blockson the page . As you click each block, the code removes that block . Load this exampleinto a canvas-compatible browser (or run it from Javascript02 .html provided in the_Solutions folder for this chapter) and see how fast you can clear all the blocks!Important If you jumped ahead to the fun example, then you’ll need to use the jQuery libraryfor the example shown here, which uses a CDN-based jQuery. Feel free to use your local copyof jQuery if you have one downloaded, or refer to the “Obtaining jQuery” section on page 293 forassistance on downloading jQuery.Canvas Block Alternate content goes here $(document).ready(function() { var canvas = document.getElementById(myCanvas); if (canvas.getContext) { var canvasContext = canvas.getContext(2d); canvasContext.fillStyle = blue; var numBlocks = 4; var canWidth = $(#myCanvas).attr(width); var canHeight = $(#myCanvas).attr(height); var blockWidth = (canWidth/numBlocks) - 2; var blockHeight = (canHeight/numBlocks) - 2; var offsetX = 0; var offsetY = 0; var colCount = 0; var numTotal = numBlocks * numBlocks;308 Chapter 16 for (i = 0; i < numTotal; i++) { canvasContext.fillRect(offsetX,offsetY, blockWidth,blockHeight); offsetX = offsetX + blockWidth + 2; colCount++; if (colCount == numBlocks) { colCount = 0; offsetY = offsetY + blockHeight + 2; offsetX = 0; } } $(#myCanvas).click(function(f) { var x = f.pageX - this.offsetLeft; var y = f.pageY - this.offsetTop; var xBlock = Math.floor((x / blockWidth)); var yBlock = Math.floor((y / blockHeight)); var xSpan = 0, ySpan = 0; if (xBlock > 0) { xSpan = xBlock * 2; } if (yBlock > 0) { ySpan = yBlock * 2; } var xPos = (blockWidth * xBlock) + xSpan; var yPos = (blockHeight * yBlock) + ySpan; canvasContext.clearRect(xPos,yPos,blockWidth, blockHeight); }); } else { // You could do something else here // because the browser doesn’t support // the canvas element. } }); Here’s what this application initially looks like: 309 Using the HTML5 TagIf you become bored with a 4 by 4 grid, change the number of blocks by changing thisline in the code, as follows:var numBlocks = 4;The code in the example will dynamical ...
Nội dung trích xuất từ tài liệu:
giáo trình HTML5 và CSS3 từng bước phần 8 307 Using the HTML5 TagThis example adds a .click() function thanks to jQuery . The .click() function examineswhere the mouse click occurred within the canvas element . It then clears the canvas anddraws a new rectangle at the point where the mouse was clicked . This example begins toshow the interactivity that’s possible with the canvas element .Finally, here’s the fun example that I promised . Building on the previous example, thecode shown here creates a larger canvas on a page, and then builds a number of blockson the page . As you click each block, the code removes that block . Load this exampleinto a canvas-compatible browser (or run it from Javascript02 .html provided in the_Solutions folder for this chapter) and see how fast you can clear all the blocks!Important If you jumped ahead to the fun example, then you’ll need to use the jQuery libraryfor the example shown here, which uses a CDN-based jQuery. Feel free to use your local copyof jQuery if you have one downloaded, or refer to the “Obtaining jQuery” section on page 293 forassistance on downloading jQuery.Canvas Block Alternate content goes here $(document).ready(function() { var canvas = document.getElementById(myCanvas); if (canvas.getContext) { var canvasContext = canvas.getContext(2d); canvasContext.fillStyle = blue; var numBlocks = 4; var canWidth = $(#myCanvas).attr(width); var canHeight = $(#myCanvas).attr(height); var blockWidth = (canWidth/numBlocks) - 2; var blockHeight = (canHeight/numBlocks) - 2; var offsetX = 0; var offsetY = 0; var colCount = 0; var numTotal = numBlocks * numBlocks;308 Chapter 16 for (i = 0; i < numTotal; i++) { canvasContext.fillRect(offsetX,offsetY, blockWidth,blockHeight); offsetX = offsetX + blockWidth + 2; colCount++; if (colCount == numBlocks) { colCount = 0; offsetY = offsetY + blockHeight + 2; offsetX = 0; } } $(#myCanvas).click(function(f) { var x = f.pageX - this.offsetLeft; var y = f.pageY - this.offsetTop; var xBlock = Math.floor((x / blockWidth)); var yBlock = Math.floor((y / blockHeight)); var xSpan = 0, ySpan = 0; if (xBlock > 0) { xSpan = xBlock * 2; } if (yBlock > 0) { ySpan = yBlock * 2; } var xPos = (blockWidth * xBlock) + xSpan; var yPos = (blockHeight * yBlock) + ySpan; canvasContext.clearRect(xPos,yPos,blockWidth, blockHeight); }); } else { // You could do something else here // because the browser doesn’t support // the canvas element. } }); Here’s what this application initially looks like: 309 Using the HTML5 TagIf you become bored with a 4 by 4 grid, change the number of blocks by changing thisline in the code, as follows:var numBlocks = 4;The code in the example will dynamical ...
Tìm kiếm theo từ khóa liên quan:
kỹ thuật html5 và css3 thủ thuật máy tính bí quyết lập trình thiết kế giao diện web thế kế wordpress mẹo tin họcTài liệu liên quan:
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 334 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 326 0 0 -
Sửa lỗi các chức năng quan trọng của Win với ReEnable 2.0 Portable Edition
5 trang 228 0 0 -
Phần III: Xử lý sự cố Màn hình xanh
3 trang 223 0 0 -
Tổng hợp 30 lỗi thương gặp cho những bạn mới sử dụng máy tính
9 trang 216 0 0 -
Sao lưu dữ liệu Gmail sử dụng chế độ Offline
8 trang 213 0 0 -
Giáo trình Bảo trì hệ thống và cài đặt phần mềm
68 trang 212 0 0 -
UltraISO chương trình ghi đĩa, tạo ổ đĩa ảo nhỏ gọn
10 trang 205 0 0 -
Hướng dẫn cách khắc phục lỗi màn hình xanh trong windows
7 trang 204 0 0 -
Chiêu 28: Trích xuất dữ liệu số trong 1 chuỗi bằng VBA
4 trang 200 0 0