2016-05-12 21 views
-1

これは私の最初の質問です!視差スクロールCSS

  1. 私はbackground-attachment: fixed;もこのプロパティが割り当てられている<div>で発生することで問題を抱えてきた: - transform: translateZ(-1px) scale(2);。実際には最初のスライドでは、背景画像は正しく表示されますが、残りのスライドでは画像は表示されません。

  2. また、クリックまたはドラッグするとスクロールバーが機能しません。

私はGoogleで何度も試したことがありますが、それは2日間です。やっと私はStackoverflowを試しました。なぜなら、私が望む特定の答えを得ることができなかったからです。

私はいくつかのリンクを逃した場合は助けてください、私を許してください。

ここで私が作っているページです - http://mynk-9.github.io/test/

を[編集]今が、私はまた、コードを追加しました。

<!DOCTYPE html> 
 
<html> 
 
\t <head> 
 
\t \t <title>Parallax Scrolling Effect</title> 
 
\t \t <style> 
 
\t \t \t body { 
 
\t \t \t \t margin: 0px; 
 
\t \t \t \t padding: 0px; 
 
\t \t \t } 
 
\t \t \t div.parallax-page { 
 
\t \t \t \t position: relative; 
 
\t \t \t \t height: 100vh; 
 
\t \t \t \t width: 100vw; 
 
\t \t \t \t overflow-y: auto; 
 
\t \t \t \t overflow-x: hidden; 
 
\t \t \t \t perspective: 1px; 
 
\t \t \t \t -webkit-perspective-origin-x: 50%; 
 
\t \t \t \t perspective-origin-x: 50%; 
 
\t \t \t } 
 
\t \t \t div.parallax-page > div.group { 
 
\t \t \t \t position: relative; 
 
\t \t \t \t height: 100%; 
 
\t \t \t \t width: 100%; 
 
\t \t \t \t left: 0px; 
 
\t \t \t \t top: 0px; 
 
\t \t \t \t 
 
\t \t \t \t -webkit-transform-style: preserve-3d; 
 
\t \t \t \t transform-style: preserve-3d; 
 
\t \t \t } 
 
\t \t \t div.parallax-page > div.group { 
 
\t \t \t \t margin-bottom: calc(100vh); 
 
\t \t \t } 
 
\t \t \t div.parallax-page > div.group:last-child { 
 
\t \t \t \t margin-bottom: -25vh; 
 
\t \t \t } 
 
\t \t \t div.parallax-page > div.group > div.background { 
 
\t \t \t \t transform: translateZ(-1px) scale(2); 
 
\t \t \t \t position: fixed; 
 
\t \t \t \t top: 0px; 
 
\t \t \t \t left: 0px; 
 
\t \t \t \t width: 100vw; 
 
\t \t \t \t height: 100%; 
 
\t \t \t \t /*background-attachment: fixed;*/ 
 
\t \t \t } 
 
\t \t \t div.parallax-page > div.group > div.slide { 
 
\t \t \t \t position: absolute; 
 
\t \t \t \t width: 50%; 
 
\t \t \t \t height: 50%; 
 
\t \t \t \t top: 50%; 
 
\t \t \t \t left: 50%; 
 
\t \t \t \t transform: translate(-50%, -50%); 
 
\t \t \t \t background-color: rgba(255,255,255,0.5); 
 
\t \t \t } 
 
\t \t \t 
 
\t \t \t div.parallax-page::-webkit-scrollbar { 
 
\t \t \t \t /*display: none;*/ 
 
\t \t \t } 
 
\t \t \t /* using formula -> scale = 1 + (translateZ * -1)/perspective */ 
 
\t \t </style> 
 
\t </head> 
 
\t 
 
\t <body> \t \t 
 
\t \t <div class="parallax-page"> 
 
\t \t \t <div class="group"> 
 
\t \t \t \t <div class="background" style="background-image: url('sample-wallpaper.svg');"></div> 
 
\t \t \t \t <div class="slide"> 
 
\t \t \t \t \t <h1 style="text-align: center;">A magical scroll!!</h1> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t \t <div class="group"> 
 
\t \t \t \t <div class="background" style="background-image: url('sample-wallpaper-2.svg');"></div> 
 
\t \t \t \t <div class="slide"> 
 
\t \t \t \t \t <h1 style="text-align: center;">A magical scroll!!</h1> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t \t <div class="group"> 
 
\t \t \t \t <div class="background" style="background-image: url('sample-wallpaper-3.svg');"></div> 
 
\t \t \t \t <div class="slide"> 
 
\t \t \t \t \t <h1 style="text-align: center;">A magical scroll!!</h1> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t \t <div class="group"> 
 
\t \t \t \t <div class="background" style="background-image: url('sample-wallpaper-5.svg');"></div> 
 
\t \t \t \t <div class="slide"> 
 
\t \t \t \t \t <h1 style="text-align: center;">A magical scroll!!</h1> 
 
\t \t \t \t </div> 
 
\t \t \t </div> 
 
\t \t </div> 
 
\t </body> 
 
</html>

+0

div.parallax-ページ> div.group> div.background'あなたは '幅を持っている'の場合:スクロールバーの上に重なって100vw' *マウスから隠す*。 '100%'に変更すると、スクロールバーが機能します。それ以外の場合は、Chromeで背景が魅力的です。 – Octopus

+0

こんにちはMayankさん、スタックオーバーフローへようこそ!質問に直接コードを追加できますか?または少なくとも、コードの "MCVE"ですか? – TylerH

+0

@Octopusあなたが言ったことを、私は100vwではなく100%にしましたが、今は小さなものです。 div.parallax-page> div.group> div.background'に 'left:-1%'のプロパティを与えようとしましたが、ギャップは消えましたが、今では –

答えて

0

<!DOCTYPE html> 
 
<html> 
 
<title>W3.CSS</title> 
 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css"> 
 
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato"> 
 
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css"> 
 
<link rel="stylesheet" href="http://www.w3schools.com/lib/w3-theme-red.css"> 
 

 
<style> 
 
body,h1,h2,h3,h4,h5,h6 {font-family: "Lato", sans-serif;} 
 
body, html { 
 
    height: 100%; 
 
    color: #777; 
 
    line-height: 1.8; 
 
} 
 

 
/* Create a Parallax Effect */ 
 
.bgimg-1, .bgimg-2, .bgimg-3 { 
 
    opacity: 0.7; 
 
    background-attachment: fixed; 
 
    background-position: center; 
 
    background-repeat: no-repeat; 
 
    background-size: cover; 
 

 
} 
 

 
/* First image */ 
 
.bgimg-1 { 
 
    background-image: url('https://pixabay.com/static/uploads/photo/2016/01/19/17/16/rainbow-background-1149610_960_720.jpg'); 
 
    min-height: 100%; 
 
} 
 

 
/* Second image */ 
 
.bgimg-2 { 
 
    background-image: url("https://i.ytimg.com/vi/4AA4qYGunr4/maxresdefault.jpg"); 
 
    min-height: 400px; 
 
} 
 

 

 
/* Adjust the position of the parallax image text */ 
 
.w3-display-middle {bottom: 45%;} 
 

 
.w3-wide {letter-spacing: 10px;} 
 

 
.w3-hover-opacity {cursor: pointer;} 
 

 

 
</style> 
 
<body> 
 

 
<!-- Navbar (sit on top) --> 
 
<div class="w3-top"> 
 
    <ul class="w3-navbar" id="myNavbar"> 
 
    <li><a href="#" class="w3-padding-large">HOME</a></li> 
 
    <li class="w3-hide-small w3-right"> 
 
     <a href="#" class="w3-padding-large w3-hover-red"><i class="fa fa-search"></i></a> 
 
    </li> 
 
    </ul> 
 
</div> 
 

 
<!-- First Parallax Image with Text --> 
 
<div class="bgimg-1 w3-opacity w3-display-container"> 
 
    <div class="w3-display-middle"> 
 
    <span class="w3-center w3-padding-xlarge w3-black w3-xlarge w3-wide w3-animate-opacity">MY <span class="w3-hide-small">WEBSITE</span> LOGO</span> 
 
    </div> 
 
</div> 
 

 
<!-- Container (About Section) --> 
 
<div class="w3-content w3-container w3-padding-64" id="about"> 
 
    <h3 class="w3-center">ABOUT ME</h3> 
 
    <p class="w3-center"><em>I love photography</em></p> 
 
    <p>We have created a fictional "personal" website/blog, and our fictional character is a hobby photographer. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, 
 
    quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa 
 
    qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p> 
 

 
    </div> 
 

 

 

 
<!-- Second Parallax Image with Portfolio Text --> 
 
<div class="bgimg-2 w3-display-container"> 
 
    <div class="w3-display-middle"> 
 
    <span class="w3-xxlarge w3-text-light-grey w3-wide">PORTFOLIO</span> 
 
    </div> 
 
</div> 
 

 
<footer class="w3-container w3-theme-dark w3-padding-16"> 
 

 
    <p>Powered by <a href="#" target="_blank">csandreas1</a></p> 
 
    
 
</footer> 
 

 

 
</body> 
 
</html>

+0

あなたがしたのは、ビューポートへの背景の添付が固定されていることです。私はその方法を知っていますが、本当に必要なのはバックグラウンドの動きでもあります。 image **しかし、通常のスクロール速度よりも相対的に遅いです。そして、はい、私はJSでやっていたかもしれませんが、性能を犠牲にして、古いデバイスでは処理できないかもしれません。すでに達成済み - [私のWebフレームワーク(ブートストラップのようなもの)](http://mynk-9.github.io/MSD-Web-Framework) –

関連する問題