An Trần Digital
No Result
View All Result
  • Thủ thuật
    • Blogspot/Blogger
    • Phần Mềm
    • WordPress
    • Plugin WordPress
  • Đồ hoạ
    • Action Photoshop
    • Preset Camera Raw
    • Preset Lightroom Mobile
    • Preset Lightroom PC
  • Themes
    • Blogger/Blogspot
    • WordPress
  • Khoá học miễn phí
    • Adobe
    • Kỹ Năng Đời Sống
    • Lập Trình – Web
    • Marketing – SEO
  • Source Code
  • Khuyến mại
Ủng hộ tôi
An Trần Digital
  • Thủ thuật
    • Blogspot/Blogger
    • Phần Mềm
    • WordPress
    • Plugin WordPress
  • Đồ hoạ
    • Action Photoshop
    • Preset Camera Raw
    • Preset Lightroom Mobile
    • Preset Lightroom PC
  • Themes
    • Blogger/Blogspot
    • WordPress
  • Khoá học miễn phí
    • Adobe
    • Kỹ Năng Đời Sống
    • Lập Trình – Web
    • Marketing – SEO
  • Source Code
  • Khuyến mại
No Result
View All Result
An Trần Digital
No Result
View All Result

Home - Source Code - Code tạo hiệu ứng tuyết rơi V2 trang trí noel

Code tạo hiệu ứng tuyết rơi V2 trang trí noel

by An Tran
12/12/2023
in Source Code
Reading Time: 3 mins read
A A
0
Code tạo hiệu ứng tuyết rơi

Nội dung bài viết

  1. Tổng quan
  2. Cách tạo code hiệu ứng tuyết rơi

Tổng quan

Trước đây mình có đăng bài về một bài cũng trang trí noel có tuyết rơi, quả châu, lá thông, người tuyết,v…v..

Bạn có thể xem chi tiết tại đây: Code tuyết rơi cho mùa giáng sinh cho website

Còn hôm nay An Trần Digital sẽ chia sẻ chỉ có tuyết rơi đơn giản, xem demo bên dưới

🤝 Ủng hộ blog

Đang định mua Hosting, VPS?

Để duy trì blog, nên blog có làm affiliate cho một số nhà cung cấp hosting. Đây đều là những bên uy tín về chất lượng và đội ngũ support nên mọi người cứ yên tâm.

Bạn click vào link bên dưới trước khi mua là đã ủng hộ mình rồi, giá vẫn giữ nguyên. Mình cảm ơn nhiều!

  • AZDIGI
    Pro Gold Hosting Giá rẻ Business Hosting Khuyên dùng VPS Platinum
  • Tino
    Business Hosting NVMe Hosting NVMe VPS
  • iNET
    Cloud VPS Web Hosting
    🎁 Nhập mã: ATD10INET (không áp dụng cho tên miền, website)
  • Nước ngoài
    Vultr Hawk Host

Cảm ơn bạn đã ủng hộ blog ❤️

Demo tuyết rơi v2

Cách tạo code hiệu ứng tuyết rơi

Bước 1: Thêm CSS bên dưới

#snowflakeContainer {
    position: absolute;
    left: 0px;
    top: 0px;
}
.snowflake {
    padding-left: 15px;
    font-family: Times, Georgia, serif;
    font-size: 14em;
    line-height: 24px;
    position: fixed;
    color: #FFFFFF;
    user-select: none;
    z-index: 1000;
}
.snowflake:hover {
    cursor: default;
  }

Bước 2: Copy đoạn mã bên dưới và dán trên thẻ </body>

<div id="snowflakeContainer">
    <p class="snowflake">*</p>
</div>

<script>  
var requestAnimationFrame = window.requestAnimationFrame ||
                            window.mozRequestAnimationFrame ||
                            window.webkitRequestAnimationFrame ||
                            window.msRequestAnimationFrame;
var transforms = ["transform",
                  "msTransform",
                  "webkitTransform",
                  "mozTransform",
                  "oTransform"];

var transformProperty = getSupportedPropertyName(transforms);
var snowflakes = [];
var browserWidth;
var browserHeight;
var numberOfSnowflakes = 50;
var resetPosition = false;
function setup() {
    window.addEventListener("DOMContentLoaded", generateSnowflakes, false);
    window.addEventListener("resize", setResetFlag, false);
}
setup();
function getSupportedPropertyName(properties) {
    for (var i = 0; i < properties.length; i++) {
        if (typeof document.body.style[properties[i]] != "undefined") {
            return properties[i];
        }
    }
    return null;
}
function Snowflake(element, speed, xPos, yPos) {    
    this.element = element;
    this.speed = speed;
    this.xPos = xPos;
    this.yPos = yPos;    
    this.counter = 0;
    this.sign = Math.random() < 0.5 ? 1 : -1;    
    this.element.style.opacity = .1 + Math.random();
    this.element.style.fontSize = 14 + Math.random() * 50 + "px";
}
Snowflake.prototype.update = function () {    
    this.counter += this.speed / 5000;
    this.xPos += this.sign * this.speed * Math.cos(this.counter) / 40;
    this.yPos += Math.sin(this.counter) / 40 + this.speed / 30;    
    setTranslate3DTransform(this.element, Math.round(this.xPos), Math.round(this.yPos));    
    if (this.yPos > browserHeight) {
        this.yPos = -50;
    }
}
function setTranslate3DTransform(element, xPosition, yPosition) {
    var val = "translate3d(" + xPosition + "px, " + yPosition + "px" + ", 0)";
    element.style[transformProperty] = val;
}
function generateSnowflakes() {    
    var originalSnowflake = document.querySelector(".snowflake");    
    var snowflakeContainer = originalSnowflake.parentNode;    
    browserWidth = document.documentElement.clientWidth;
    browserHeight = document.documentElement.clientHeight;   
    for (var i = 0; i < numberOfSnowflakes; i++) {        
        var snowflakeClone = originalSnowflake.cloneNode(true);
        snowflakeContainer.appendChild(snowflakeClone);       
        var initialXPos = getPosition(50, browserWidth);
        var initialYPos = getPosition(50, browserHeight);
        var speed = 5+Math.random()*40;        
        var snowflakeObject = new Snowflake(snowflakeClone,
                                            speed,
                                            initialXPos,
                                            initialYPos);
        snowflakes.push(snowflakeObject);
    }    
    snowflakeContainer.removeChild(originalSnowflake);    
    moveSnowflakes();
}
function moveSnowflakes() {
    for (var i = 0; i < snowflakes.length; i++) {
        var snowflake = snowflakes[i];
        snowflake.update();
    }    
    if (resetPosition) {
        browserWidth = document.documentElement.clientWidth;
        browserHeight = document.documentElement.clientHeight;

        for (var i = 0; i < snowflakes.length; i++) {
            var snowflake = snowflakes[i];

            snowflake.xPos = getPosition(50, browserWidth);
            snowflake.yPos = getPosition(50, browserHeight);
        }

        resetPosition = false;
    }

    requestAnimationFrame(moveSnowflakes);
}
function getPosition(offset, size) {
    return Math.round(-1*offset + Math.random() * (size+2*offset));
}
function setResetFlag(e) {
    resetPosition = true;
}

</script>

Vậy là mình đã hướng dẫn share code tạo hiệu ứng tuyết rơi trang trí noel mùa giáng sinh cho website cực đơn giản phải không nào. 

Hãy cùng xem thành quả, chúc các bạn thành công !!!

Tags: code tạo hiệu ứng tuyết rơicode tuyết rơi js
Previous Post

Cách tắt tự động cập nhật WordPress Core, Theme, Plugin

Next Post

Tổng hợp code pháo hoa cho website HTML đẹp

An Tran

An Tran

Tôi là An Trần, thuộc thế hệ 9X. Hiện tại đang làm nhân viên cắt cỏ tại sân Old Trafford.

Related Posts

cloudflare security audit skill

Quét lỗ hổng bảo mật cho vibe coding bằng Security Audit Skill

01/11/2026
Cách Đồng bộ Google Sheet với Calendar bằng Google Apps Script

Cách Đồng bộ Google Sheet với Calendar bằng Google Apps Script

27/01/2026
Prompt AI là gì

Prompt AI là gì? Các loại và cách viết Prompt hiệu quả nhất

19/02/2025
Source Code Web Bán Hàng Thời Trang ASP.NET MVC giá rẻ

Source Code Web Bán Hàng Thời Trang ASP.NET MVC

27/04/2024
Next Post
Code pháo hoa chơ website

Tổng hợp code pháo hoa cho website HTML đẹp

Để lại một bình luận Hủy

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

BÀI VIẾT NGẪU NHIÊN

udemy-course-100%-free-off-coupon-antrandigital

Chia sẻ 28+ Coupon khoá học lập trình Udemy miễn phí

08/07/2020
Preset Lightroom Mobile đi siêu thị tone hàn quốc đẹp

Preset Lightroom Mobile đi siêu thị tone hàn quốc đẹp

15/03/2022
digital_marketing_23_course_in_1_antrandigital

Share khoá học Digital Marketing Masterclass 23 Courses in 1

16/06/2020
tai_microsoft_powertoys_antrandigital

Tải Microsoft Powertoys – công cụ cực hay cho windows

29/06/2020

HOSTING / VPS KHUYÊN DÙNG

🔥 Hosting đề xuất & mã giảm giá
logo Hawk Host

Hosting quốc tế giá rẻ, chạy LiteSpeed, có máy chủ Singapore cho tốc độ tốt tại Việt Nam. Xem ngay

logo AZDIGI

Hosting WordPress chất lượng cao. Support tốt 24/7. Xem ngay

Có mãlogo iNET

Nhà cung cấp hosting, tên miền lâu đời ở Việt Nam. Click để nhận mã ưu đãi. Xem ngay

-10%logo TinoHost

Hosting WordPress chất lượng cao. Support tốt. Dùng thử 7 ngày. Click để nhận mã giảm 10% ngay. Xem ngay

logo noel retina

An Trần Digital là blog cá nhân chia sẻ preset lightroom, camera raw từ máy tính đến mobile, template blogspot, theme wordpress và các khoá học khác hoàn toàn miễn phí.

DMCA.com Protection Status

Xem nhiều nhất ngày

Share 5 Template Blogspot bán hàng miễn phí mới nhất

Tải The Events Calendar PRO miễn phí

Tiện ích

Công cụ tiện ích

Tạo QR Code miễn phí

HTML Cleaner

Chèn Watermark vào ảnh

Công cụ tạo Schema Markup

Kiểm tra độ dài thẻ meta

Về An Trần Digital

Giới thiệu về tôi

Bảo mật

Hợp tác

Bản quyền

Liên hệ

Bảng giá Hosting VPS

© 2020 - 2026 An Trần Digital - All Rights Reserved

No Result
View All Result
  • Thủ thuật
    • Blogspot/Blogger
    • Phần Mềm
    • WordPress
    • Plugin WordPress
  • Đồ hoạ
    • Action Photoshop
    • Preset Camera Raw
    • Preset Lightroom Mobile
    • Preset Lightroom PC
  • Themes
    • Blogger/Blogspot
    • WordPress
  • Khoá học miễn phí
    • Adobe
    • Kỹ Năng Đời Sống
    • Lập Trình – Web
    • Marketing – SEO
  • Source Code
  • Khuyến mại

© 2020 - 2026 An Trần Digital - All Rights Reserved

popup affiliate

Cookie & trải nghiệm An Trần Digital

Cookies được sử dụng nhằm ghi nhận các thiết lập cần thiết để website hoạt động ổn định và hỗ trợ trải nghiệm của bạn tốt hơn.

Danh sách Cookies

Việc từ chối một số loại cookie sẽ có thể ảnh hưởng đến hoạt động của một số chức năng trên website

Tìm hiểu thêm tại Chính sách thu thập và xử lý dữ liệu cá nhân.