TAILIEUCHUNG - Học JavaScript qua ví dụ part 46

Thay thế hình ảnh động các với các tài sản src Bằng cách thay đổi giá trị tài sản được giao src của ảnh, nó có thể tự động thay thế một hình ảnh với nhau. Bạn có thể tạo ra một loạt các hình ảnh với các Array () xây dựng, và chỉ định bất kỳ một trong những hình ảnh đối với tài sản src của hình ảnh JavaScript [] mảng. | 428 Chapter 12 Working with Images and Links Replacing Images Dynamically with the src Property By changing the value assigned to the src property of an image it is possible to dynamically replace one image with another. You can create an array of images with the Array constructor and assign any one of these images to the src property of the JavaScript images array. EXAMPLE html head title HTML Images title script type text javascript 1 var myImages new Array 2 index_val 0 3 function next_image 4 index_val 5 if index_val 6 babypic .src myImages index_val could say or 0 .src 7 else index_val 0 babypic .src myImages index_val 8 function previous_image index_val-- 9 if index_val 0 babypic .src myImages index_val 10 else index_val - 1 babypic .src myImages index_val script head body div align center h2 Baby Gallery h2 11 img name babypic id babypic src width 329 height 440 br From the Library of Working with Imagemaps 429 EXAMPLE continued 12 a href JavaScript next_image View next baby br a 13 a href JavaScript previous_image View previous baby br a div body html EXPLANATION 1 The array myImages consisting of four images is created by the Array constructor. 2 The index value for the array is assigned to a variable called index_val. 3 A function called next_image is defined. When called the function will cause the next image in the array to be displayed. 4 By increasing the value of the index the next image in the array will be accessed. 5 As long as the end of the array hasn t been reached the block will be entered and the new image displayed. 6 The name of the image babypic is used as an index into the images array to reference the default image by name. By assigning a new image from the mylmages array to the image s src property the current image will .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.