Edrol97
Bronze Coder
Hi all. This is the link to a new website page of mine for a whack a mole game. I want the hole background to have worms moving along it and for it not to effect the game's location on the page. How do I do this?
By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!Hi all. This is the link to a new website page of mine for a whack a mole game. I want the hole background to have worms moving along it and for it not to effect the game's location on the page. How do I do this?
<!-- HTML -->
<div class="background">
</div><div class="game">
<!-- Your game code here -->
</div>
<!-- CSS -->
<style>
.background { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: -1; overflow: hidden; }
.worm { position: absolute; width: 50px; height: 10px; background-color: brown; border-radius: 5px; animation: moveWorms 10s linear infinite; }
/* Worm animation */
@keyframes moveWorms { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }</style>
div{
background-image:
url('img/worm.gif'),
url('img/worm.gif'),
url('img/worm.gif'),
url('img/worm.gif');
background-position:
left top,
center top,
right top,
center;
background-repeat: no-repeat; /* or repeat for all if needed */
}
Managed to do it as so:It is also possible to use multiple background-images for an element, such as a div.
CSS:div{ background-image: url('img/worm.gif'), url('img/worm.gif'), url('img/worm.gif'), url('img/worm.gif'); background-position: left top, center top, right top, center; background-repeat: no-repeat; /* or repeat for all if needed */ }
Adjust all as necessary for your needs.
Nice. You might want to put overflow:hidden on the gif's wrappers to avoid the unwanted horizontal scrollbars
Odd, there are no horizontal scrollbars on my live or local version. Can you show me what you see?Nice. You might want to put overflow:hidden on the gif's wrappers to avoid the unwanted horizontal scrollbars
Odd, there are no horizontal scrollbars on my live or local version. Can you show me what you see?
Code Forum is a community platform where coding enthusiasts can connect with other developers, engage in discussions, ask for help, and share their knowledge with a supportive community. It's a perfect place to improve your coding skills and to find a community of like-minded individuals who share your passion for coding.
We use essential cookies to make this site work, and optional cookies to enhance your experience.