Tạo hiệu ứng tuyết rơi ngày Noel cho blogspot

- [tintuc]
Noel 24-25/12 mỗi năm sắp đến. Đây là dịp đi chơi và cũng như cho các blogger chúng ta trang hoàn cho blog của mình.
Đơn giản cho việc trang trí blog là tạo hiệu ứng tuyết rơi cho hợp với không khí Noel.

Chúng ta cùng tiến hành!

Chỉ cần 1 bước và chèn code cài đặt bên dưới trước thẻ /body là chúng ta sẽ có ngay hiệu ứng này.
[code]


Code #1 Tạo tuyết rơi hạt to cho Blogspot

<!-- Tuyet -->
<style>
#snowflakeContainer {
    position: absolute;
    left: 0px;
    top: 0px;
}
.snowflake {
    padding-left: 15px;
    font-family: Cambria, Georgia, serif;
    font-size: 14px;
    line-height: 24px;
    position: fixed;
    color: #FFFFFF;
    user-select: none;
    z-index: 1000;
}
.snowflake:hover {
    cursor: default;
}
  </style>
<div id='snowflakeContainer'>
<p class='snowflake'>*</p>
</div>
<script>// The star of every good animation
var requestAnimationFrame = window.requestAnimationFrame ||
                            window.mozRequestAnimationFrame ||
                            window.webkitRequestAnimationFrame ||
                            window.msRequestAnimationFrame;
var transforms = ["transform",
                  "msTransform",
                  "webkitTransform",
                  "mozTransform",
                  "oTransform"];
                 
var transformProperty = getSupportedPropertyName(transforms);
// Array to store our Snowflake objects
var snowflakes = [];
// Global variables to store our browser's window size
var browserWidth;
var browserHeight;
// Specify the number of snowflakes you want visible
var numberOfSnowflakes = 50;
// Flag to reset the position of the snowflakes
var resetPosition = false;
//
// It all starts here...
//
function setup() {
    window.addEventListener("DOMContentLoaded", generateSnowflakes, false);
    window.addEventListener("resize", setResetFlag, false);
}
setup();
//
// Vendor prefix management
//
function getSupportedPropertyName(properties) {
    for (var i = 0; i < properties.length; i++) {
        if (typeof document.body.style[properties[i]] != "undefined") {
            return properties[i];
        }
    }
    return null;
}
//
// Constructor for our Snowflake object
//
function Snowflake(element, radius, speed, xPos, yPos) {
    // set initial snowflake properties
    this.element = element;
    this.radius = radius;
    this.speed = speed;
    this.xPos = xPos;
    this.yPos = yPos;
 
    // declare variables used for snowflake's motion
    this.counter = 0;
    this.sign = Math.random() < 0.5 ? 1 : -1;
 
    // setting an initial opacity and size for our snowflake
    this.element.style.opacity = .1 + Math.random();
    this.element.style.fontSize = 12 + Math.random() * 50 + "px";
}
//
// The function responsible for actually moving our snowflake
//
Snowflake.prototype.update = function () {
    // using some trigonometry to determine our x and y position
    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;
    // setting our snowflake's position
    setTranslate3DTransform(this.element, Math.round(this.xPos), Math.round(this.yPos));
 
    // if snowflake goes below the browser window, move it back to the top
    if (this.yPos > browserHeight) {
        this.yPos = -50;
    }
}
//
// A performant way to set your snowflake's position
//
function setTranslate3DTransform(element, xPosition, yPosition) {
    var val = "translate3d(" + xPosition + "px, " + yPosition + "px" + ", 0)";
    element.style[transformProperty] = val;
}
//
// The function responsible for creating the snowflake
//
function generateSnowflakes() {
 
    // get our snowflake element from the DOM and store it
    var originalSnowflake = document.querySelector(".snowflake");
 
    // access our snowflake element's parent container
    var snowflakeContainer = originalSnowflake.parentNode;
 
    // get our browser's size
    browserWidth = document.documentElement.clientWidth;
    browserHeight = document.documentElement.clientHeight;
         
    // create each individual snowflake
    for (var i = 0; i < numberOfSnowflakes; i++) {
 
        // clone our original snowflake and add it to snowflakeContainer
        var snowflakeCopy = originalSnowflake.cloneNode(true);
        snowflakeContainer.appendChild(snowflakeCopy);
        // set our snowflake's initial position and related properties
        var initialXPos = getPosition(50, browserWidth);
        var initialYPos = getPosition(50, browserHeight);
        var speed = 5+Math.random()*40;
        var radius = 4+Math.random()*10;
     
        // create our Snowflake object
        var snowflakeObject = new Snowflake(snowflakeCopy,
                                            radius,
                                            speed,
                                            initialXPos,
                                            initialYPos);
        snowflakes.push(snowflakeObject);
    }
 
    // remove the original snowflake because we no longer need it visible
    snowflakeContainer.removeChild(originalSnowflake);
 
    // call the moveSnowflakes function every 30 milliseconds
    moveSnowflakes();
}
//
// Responsible for moving each snowflake by calling its update function
//
function moveSnowflakes() {
    for (var i = 0; i < snowflakes.length; i++) {
        var snowflake = snowflakes[i];
        snowflake.update();
    }
 
    // Reset the position of all the snowflakes to a new value
    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);
}
//
// This function returns a number between (maximum - offset) and (maximum + offset)
//
function getPosition(offset, size) {
    return Math.round(-1*offset + Math.random() * (size+2*offset));
}
//
// Trigger a reset of all the snowflakes' positions
//
function setResetFlag(e) {
    resetPosition = true;
}</script>

Code 2: Tạo tuyết rơi hạt nhỏ cho blogspot 

<style type="text/css">
.snow-container{position:fixed;width:100%;max-width:100%;z-index:99999;pointer-events:none;overflow:hidden;top:0;height:100%}
.snow{display:block;position:absolute;z-index:2;top:0;right:0;bottom:0;left:0;pointer-events:none;-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0);-webkit-animation:snow linear infinite;animation:snow linear infinite}
.snow.foreground{background-image:url("https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcyIA3eLQQnZpU-mgXHzthqWwRx7nIhEr6AGyCkXB5QEE4X-ElaWMtm9ncgu9a2D_5kfxm7s-TnMXKdTpMZAKQ7ISZSaQLoVJnYieb99qaK3Eayl5o_6sefU6cqzCdkX34X6mTwndAZYA/s1600/snow-effect-s-min.png");-webkit-animation-duration:15s;animation-duration:10s}
.snow.foreground.layered{-webkit-animation-delay:7.5s;animation-delay:7.5s}
.snow.middleground{background-image:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg0f8XQa7KiqOWkhwTdqMKj_yY-OSiTMW3ZnmH0qpL5_tWWB_hiKhfB_ZChtmokr2MHbusIzQLZeNEpEHLa2Eswxqz4xZFq3NfXRuctqbTIR3DgBZIMbzs1xepJAbMe0iKsvHHfVL_wlF8/s320/snow-medium-m-min.png);-webkit-animation-duration:20s;animation-duration:15s}
.snow.middleground.layered{-webkit-animation-delay:10s;animation-delay:10s}
.snow.background{background-image:url(https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKKip3IeTKdoZSSGBSIryFaDXo-xeYRsfPPQNqEaFU0O-fabFzA9UjjfYzPKCgYogxil9swWjN8d-_DW7Z5c6VCGbesoGD9S_PXht24qO9l1TCAHoETNtfkKJsqyObmZ18FXG0tq7Cu-o/s320/snow-effect-l-min.png);-webkit-animation-duration:25s;animation-duration:20s}
.snow.background.layered{-webkit-animation-delay:12.5s;animation-delay:12.5s}
@-webkit-keyframes snow{0%{-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}100%{-webkit-transform:translate3d(5%,100%,0);transform:translate3d(5%,100%,0)}}
@keyframes snow{0%{-webkit-transform:translate3d(0,-100%,0);transform:translate3d(0,-100%,0)}100%{-webkit-transform:translate3d(5%,100%,0);transform:translate3d(5%,100%,0)}}
</style>
<div class='snow-container'><div class='snow foreground'/><div class='snow foreground layered'/><div class='snow middleground'/><div class='snow middleground layered'/><div class='snow background'/><div class='snow background layered'/></div>
Chúc bạn thành công! 
[/tintuc]
Huỳnh Phụng Blogger

TLQT là Blog chia sẻ kiến thức về Marketing, Digital Marketing, Kinh nghiệm làm SEO, Tối ưu Website và nhiều thứ khác

Đăng nhận xét

➔ Gửi kèm hình ảnh trên bài viết để được hỗ trợ tốt nhất.
➔ Để bình luận kèm hình ảnh, bạn vào trang Upload Ảnh, kéo thả để Upload hình ảnh lên.
➔ Bạn dán URL link hình ảnh vào khung bình luận và ấn Xuất bản, ảnh sẽ được tự động tải lên.
➔ Không spam trong khung bình luận, hạn chế viết tắt.
➔ Tích vào ô Thông báo cho tôi (Notify me) để nhận thông báo phản hồi của Admin

Mới hơn Cũ hơn

POST ADS1

POST ADS 2