Answers for "moving background css"

CSS
20

css animation

CSS animation properties template:
{
   animation-name: anima-name;
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-delay: 2s;
    animation-direction: reverse | normal | alternate | alternate-reverse ; 
  animation-timing-function: ease | ease-out | ease-in | ease-in-out | linear | cubic-bezier(x1, y1, x2, y2) (e.g. cubic-bezier(0.5, 0.2, 0.3, 1.0)); 
  animation-fill-mode:forwards | backwards | both | none;
}
@keyframes anima-name {
  from {
   background-position:right;
  }
  to {
    background-position:left;
  }
}
@keyframes anima-name {
  0% {
    background-color: red;
  }
  50% {
    background-color: green;
  }
  100% {
    background-color: red;
  }
}
Posted by: Guest on June-18-2020
1

moving background

first create a box collider 2d and a rigidbody2d THEN ADD THIS SCRIPT TO YOUR BACKGROUND
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BackgroundScroller : MonoBehaviour
{
    public BoxCollider2D collider;
    public Rigidbody2D rb;

    private float width;
    private float scrollSpeed = -2f;
     
    // Start is called before the first frame update
    void Start()
    {
        collider = GetComponent<BoxCollider2D>();
        rb = GetComponent<Rigidbody2D>();

        width = collider.size.x;
        collider.enabled = false;

        rb.velocity = new Vector2(scrollSpeed, 0);
    }

    // Update is called once per frame
    void Update()
    {
        if (transform.position.x < -width)
        {
            Vector2 resetPosition = new Vector2(width * 2f, 0);
            transform.position = (Vector2)transform.position + resetPosition;
        }
    }
}
Posted by: Guest on June-23-2021
20

css animation

CSS animation properties template:
{
   animation-name: anima-name;
    animation-duration: 1s;
    animation-iteration-count: infinite;
    animation-delay: 2s;
    animation-direction: reverse | normal | alternate | alternate-reverse ; 
  animation-timing-function: ease | ease-out | ease-in | ease-in-out | linear | cubic-bezier(x1, y1, x2, y2) (e.g. cubic-bezier(0.5, 0.2, 0.3, 1.0)); 
  animation-fill-mode:forwards | backwards | both | none;
}
@keyframes anima-name {
  from {
   background-position:right;
  }
  to {
    background-position:left;
  }
}
@keyframes anima-name {
  0% {
    background-color: red;
  }
  50% {
    background-color: green;
  }
  100% {
    background-color: red;
  }
}
Posted by: Guest on June-18-2020
1

moving background

first create a box collider 2d and a rigidbody2d THEN ADD THIS SCRIPT TO YOUR BACKGROUND
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BackgroundScroller : MonoBehaviour
{
    public BoxCollider2D collider;
    public Rigidbody2D rb;

    private float width;
    private float scrollSpeed = -2f;
     
    // Start is called before the first frame update
    void Start()
    {
        collider = GetComponent<BoxCollider2D>();
        rb = GetComponent<Rigidbody2D>();

        width = collider.size.x;
        collider.enabled = false;

        rb.velocity = new Vector2(scrollSpeed, 0);
    }

    // Update is called once per frame
    void Update()
    {
        if (transform.position.x < -width)
        {
            Vector2 resetPosition = new Vector2(width * 2f, 0);
            transform.position = (Vector2)transform.position + resetPosition;
        }
    }
}
Posted by: Guest on June-23-2021

Browse Popular Code Answers by Language