Parallax Effect CSS

Parallax Effect CSS

Halo teman-teman YELLOWWEB, kita berjumpa lagi ya diartikel terbaru. Nah untuk artikel kali ini, kita akan mencoba mencari tahu bagaimana cara membuat Parallax Effect dengan menggunakan CSS.

Parallax pada website ini sebenarnya adalah teknik khusus dimana benda yang berada di latarbelakang (background) bergerak lebih lambat dibandingkan dengan yang berada di latar bagian depan (frontground), sehingga akan menimbulkan efek 3D, meskipun grafik yang dibuat menggunakan 2D.

parallax-scrolling-mario.gif

Parallax Effect CSS

Gambar yang diatas contoh Parallax pada game super mario.

Yuk kita coba buat Parallax Effect dengan menggunakan CSS 😊

buatlah file dengan nama index.html

<!DOCTYPE html>
<html>
<head>
	<title>Parallax Effect CSS | www.yellowweb.id</title>
	<style type="text/css">
		#wrapper{
			width: 1200px;
			margin: auto;
		}

		#wrapper img{
			width: 100%;
		}

		section{
			background-color: #ffffff;
		}

		.para1{
			background-image: url("porche.jpeg");
			height: 500px;
			background-size: cover;
			background-attachment: fixed;
			background-repeat: no-repeat;
			background-position: center;
		}

		.para2{
			background-image: url("ferrari2.jpeg");
			height: 500px;
			background-size: cover;
			background-attachment: fixed;
			background-repeat: no-repeat;
			background-position: center;
		}

		.para3{
			background-image: url("ferrari.jpeg");
			height: 500px;
			background-size: cover;
			background-attachment: fixed;
			background-repeat: no-repeat;
			background-position: center;
		}
	</style>
</head>
<body>
	<div id="wrapper">
		<p>Gulir ke atas atau ke bawah</p>
		<div class="para1"></div>
		<section>
			<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
			<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
			<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
		</section>
		<div class="para2"></div>
		<section>
			<p>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>
			<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
			<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.</p>
			<p>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
		</section>
		<div class="para3"></div>
	</div>

</body>
</html>

Untuk CSS saya mencoba meletakkan di tag atau dengan embeded css

<style type="text/css">
		#wrapper{
			width: 1200px;
			margin: auto;
		}

		#wrapper img{
			width: 100%;
		}

		section{
			background-color: #ffffff;
		}

		.para1{
			background-image: url("porche.jpeg");
			height: 500px;
			background-size: cover;
			background-attachment: fixed;
			background-repeat: no-repeat;
			background-position: center;
		}

		.para2{
			background-image: url("ferrari2.jpeg");
			height: 500px;
			background-size: cover;
			background-attachment: fixed;
			background-repeat: no-repeat;
			background-position: center;
		}

		.para3{
			background-image: url("ferrari.jpeg");
			height: 500px;
			background-size: cover;
			background-attachment: fixed;
			background-repeat: no-repeat;
			background-position: center;
		}
	</style>

Berikut ini hasilnya dan selamat mencoba ingat selau berkreasi

Comments are closed.