An Trần Digital
No Result
View All Result
Thứ Sáu, Tháng Sáu 27, 2025
  • 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
  • Mã giảm giá Shopee, Tiki
Ủ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
  • Mã giảm giá Shopee, Tiki
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
14
SHARES
178
VIEWS

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

Để duy trì blog ngoài link rút gọn & mình có làm aff cho 1 số bên hosting.

Các nhà cung cấp uy tín về mặt chất lượng & đội ngũ support nên mọi người cứ yên tâm.

Nếu bạn đang có ý định mua Hosting, VPS mình có list dưới đây các bạn click vào link trước khi mua để ủng hộ mình nhé. Mình cảm ơn nhiều

  • Azdigi: Giá rẻ thì dùng gói Pro Gold Hosting còn chất lượng hơn thì em khuyên dùng Business Hosting. Có điều kiện thì lên VPS nhé
  • Tino: Business Hosting, NVMe Hosting và NVMe VPS
  • iNet: Cloud VPS và Web Hosting

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

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
Code pháo hoa chơ website

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

13/12/2023
Code hiệu ứng hoa mai rơi cho blog/website

Code hiệu ứng hoa mai rơi cho blog/website

02/01/2023
Next Post
Code pháo hoa chơ website

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

Subscribe
Notify of
guest

Hãy dùng tên của bạn khi comment, không sử dụng keyword trong ô Tên. Xin cảm ơn!

guest

Hãy dùng tên của bạn khi comment, không sử dụng keyword trong ô Tên. Xin cảm ơn!

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

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

chia-se-powerpoint-template-sieu-sin-antrandigital

Chia sẻ PowerPoint Templates Siêu Xịn Giá Vài Trăm Đô

04/07/2020
Hướng dẫn xoá category trong url wordpress

Hướng dẫn cách xoá Category trong Url wordpress

28/04/2022
chia-se-preset-camera-raw-han-quoc-antrandigital

Chia sẻ preset camera raw hàn quốc xẻng blend ảnh đẹp

30/12/2020
Cách ẩn widget trên giao diện điện thoại cho website wordpress an trần digital

[WordPress] Cách ẩn Widget trên giao diện mobile cho website

05/01/2022

HOSTING / VPS KHUYÊN DÙNG

logo azdigi

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

logo inet

Nhà cung cấp hosting, tên miền có lâu đời ở Việt Nam. Xem ngay

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


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

Comments gần đây

  • An Tran
    Quản lý
    trong Share Key Screaming Frog SEO Spider
  • gia cat luoing trong Share Key Screaming Frog SEO Spider
  • An Tran
    Quản lý
    trong Share Key Screaming Frog SEO Spider

Xem nhiều nhất ngày

Share Key Screaming Frog SEO Spider

2000+ Preset Camera Raw chỉnh màu ảnh đẹp nhất

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ệ

Donate

© 2020 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
  • Mã giảm giá Shopee, Tiki

© 2020 An Trần Digital - All Rights Reserved

wpDiscuz

Đồng ý sử dụng cookie

Những cookie này giúp trang web ghi nhớ thông tin về lần truy cập của bạn. Nhờ đó, bạn có thể truy cập trang web này dễ dàng hơn vào lần tới và trang web cũng trở nên hữu ích hơn cho bạn. Tìm hiểu thêm