2013-07-16 73 views
2

目前我正在一個網站上工作,我遇到了很多困難。基本上,我正在試圖製作一個+形狀的網站,該網站應該具有雙向滾動系統。我努力使網站看起來是這樣的:在+形網站上水平和垂直滾動

權證è
C C C
權證è

其中E是空的,不可見的空間。 C是一個實際的div,包含內容。所有內容div都將鏈接到彼此,因此用戶可以訪問該網站的其他部分。

因爲我的jQuery和JavaScript不是最好的,我有很多麻煩讓網站滾動鏈接單擊操作。我終於設法讓它與jQuery scrollTo庫一起工作,但現在我有一個不同的問題。用戶現在仍然可以滾動到網站的「空白」部分,這是一個很大的可用性問題。我試圖通過使用overflow:hidden來關閉這個空的空間,但是這打破了整個滾動系統。同時,我還希望在進入網站時(box5),首先顯示中間內容div。但是因爲我的jQuery/Javascript技能目前非常糟糕,所以我很難讓這個網站正常工作。

任何幫助,或向正確的方向輕推將不勝感激!

這是我目前的工作:

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<!--<link href="css/reset.css" rel="stylesheet" type="text/css" />--> 
<link href="css/style.css" rel="stylesheet" type="text/css" /> 
    <!-- Load jQuery (newer versions will not work) --> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 
    <!-- Load ScrollTo --> 
    <script src="http://flesler-plugins.googlecode.com/files/jquery.scrollTo-1.4.2-min.js"></script> 
    <!-- Load LocalScroll --> 
    <script src="http://flesler-plugins.googlecode.com/files/jquery.localscroll-1.2.7-min.js"></script> 
    <!-- Load Link Scrolling--> 
    <script src="js/init.js"></script> 
</head> 

<body> 

<div id="box-links"> 
<!-- Temporary table as site reference --> 
<table width="400" border="1" cellspacing="1" cellpadding="1"> 
    <tr> 
    <td>(Empty)</a></td> 
    <td><a href="#box2" class="box2link">box2 (News)</a></td> 
    <td>(Empty)</a></td> 
    </tr> 
    <tr> 
    <td><a href="#box4" class="box4link">box4 (Day 1)</a></td> 
    <td><a href="#box5" class="box5link">box5 (Home/Index)</a></td> 
    <td><a href="#box6" class="box6link">box6 (Day 2)</a></td> 
    </tr> 
    <tr> 
    <td>(Empty)</td> 
    <td><a href="#box8" class="box8link">box8 (Unspecified)</a></td> 
    <td>(Empty)</td> 
    </tr> 
</table> 
</div><!-- end box-links--> 

<div id="master_container"> 

<div id="box2" class="container"> 
</div> 

<div id="box4" class="container"> 
</div> 
<div id="box5" class="container"> 
</div> 
<div id="box6" class="container"> 
</div> 

<div id="box8" class="container"> 
</div> 

</div> <!-- end master container--> 

<footer> 

</footer> 

</body> 
</html> 

的style.css

@charset "utf-8"; 

/* Temporary placement of reset.css */ 

/* http://meyerweb.com/eric/tools/css/reset/ 
    v2.0 | 20110126 
    License: none (public domain) 
*/ 

/*table, tr, th, td, tijdelijk uitgehaald */ 
html, body, div, span, applet, object, iframe, 
h1, h2, h3, h4, h5, h6, p, blockquote, pre, 
a, abbr, acronym, address, big, cite, code, 
del, dfn, em, img, ins, kbd, q, s, samp, 
small, strike, strong, sub, sup, tt, var, 
b, u, i, center, 
dl, dt, dd, ol, ul, li, 
fieldset, form, label, legend, 
caption, tbody, tfoot, thead, 
article, aside, canvas, details, embed, 
figure, figcaption, footer, header, hgroup, 
menu, nav, output, ruby, section, summary, 
time, mark, audio, video { 
    margin: 0; 
    padding: 0; 
    border: 0; 
    font-size: 100%; 
    font: inherit; 
    vertical-align: baseline; 
} 
/* HTML5 display-role reset for older browsers */ 
article, aside, details, figcaption, figure, 
footer, header, hgroup, menu, nav, section { 
    display: block; 
} 
body { 
    line-height: 1; 
} 
ol, ul { 
    list-style: none; 
} 
blockquote, q { 
    quotes: none; 
} 
blockquote:before, blockquote:after, 
q:before, q:after { 
    content: ''; 
    content: none; 
} 
table { 
    border-collapse: collapse; 
    border-spacing: 0; 
} 

/*====================================================================================*/ 







html, body { 
    width: 100%; 
    height: 100%; 
} 


#master_container{ 
    width:300%; 
    height:300%; 
    min-width:3000px; 

} 

.container{ 
    width: 33.2%; 
    height: 33.3%; 
    float: left; 
    background-color: #0CF; 
    border: 2px dashed #000; 
} 

    #box2, #box8{ 
     margin: 0 33.3% 0 33.3%; 
    } 

footer{ 
    position:fixed; 
    width:100%; 
    height:50px; 
    background-color:#F00; 
    bottom:0px; 
} 

init.js

jQuery(function($){ 
    /** 
    * Most jQuery.localScroll's settings, actually belong to jQuery.ScrollTo, check it's demo for an example of each option. 
    * @see http://flesler.demos.com/jquery/scrollTo/ 
    * You can use EVERY single setting of jQuery.ScrollTo, in the settings hash you send to jQuery.LocalScroll. 
    */ 

    // The default axis is 'y', but in this demo, I want to scroll both 
    // You can modify any default like this 
    $.localScroll.defaults.axis = 'xy'; 
    // When the document is loaded... 
    $(document).ready(function() 
    { 
     // Scroll the whole document 
     $('#box-links').localScroll({ 
      target:'body', 
      queue:true, 
      duration:1000, 
      hash:true, 
      onBefore:function(e, anchor, $target){ 
       // The 'this' is the settings object, can be modified 
      }, 
      onAfter:function(anchor, settings){ 
       // The 'this' contains the scrolled element (#content) 
      } 

     }); 


    }); 
}); 

請原諒我,如果我沒到位代碼在這裏正確。

+1

所以你基本上要一個單頁網站 – 2013-07-16 18:31:46

+0

搜索「單頁網站」,您可能會發現您正在搜索的內容。 – putvande

+0

我曾看過單頁網站,這就是我對scrollTo Library的瞭解。儘管大多數單頁網站不進行垂直和水平滾動。至少,我發現很難找到關於這方面的教程。 – user2588534

回答

2

昨天我有同樣的想法,並設法弄清楚。我的例子使用scrollTo插件和一些簡單的jquery動畫。這可能會被清理一下,但這是一個開始。

這裏是fiddle

的HTML

<section class="right"> 
     <h1>Right</h1> 
     <h2><a href="#" class="toggle-left">Left</a></h2> 
</section> 

<section class="left"> 
    <h1>Left</h1> 
    <h2><a href="#" class="toggle-right">Right</a></h2> 
</section> 

<section class="middle"> 
    <h1>Home/middle</h1> 
    <h2><a href="#" class="toggle-up">up</a></h2> 
    <h2><a href="#" class="toggle-down">down</a></h2> 
    <h2><a href="#" class="toggle-left">Left</a></h2> 
    <h2><a href="#" class="toggle-right">Right</a></h2> 
</section> 

<section class="top"> 
    <h1>Top</h1> 
    <h2><a href="#" class="toggle-down">down</a></h2> 
</section> 

<section class="bottom"> 
    <h1>Bottom</h1> 
    <h2><a href="#" class="toggle-up">up</a></h2> 
</section> 

jQuery的

jQuery(document).ready(function ($) { 
    var width = $(window).width(); 
    var height = $(window).height(); 

    $('html').scrollTo('+=' + width, 0, { 
     axis: 'x' 
    }) 

    //left & right section 
    $(".toggle-right").click(function() { 
     $('html').scrollTo('+=' + width, 800, { 
      axis: 'x' 
     }); 
    }); 
    $(".toggle-left").click(function() { 
     $('html').scrollTo('-=' + width, 800, { 
      axis: 'x' 
     }); 
    }); 

    //top section 
    $(".top .toggle-down").click(function (e) { 
     e.preventDefault(); 
     $('.top').animate({ 
      top: "-100%", 
     }, 800); 
     $('.middle').animate({ 
      top: "0", 
     }, 800); 
    }); 

    //middle section 
    $(".middle .toggle-up").click(function (e) { 
     e.preventDefault(); 
     $('.top').animate({ 
      top: "0", 
     }, 800); 
     $('.middle').animate({ 
      top: "100%", 
     }, 800); 
    }); 
    $(".middle .toggle-down").click(function (e) { 
     e.preventDefault(); 
     $('.bottom').animate({ 
      bottom: "0", 
     }, 800); 
     $('.middle').animate({ 
      top: "-100%", 
     }, 800); 
    }); 

    //bottom section 
    $(".bottom .toggle-up").click(function (e) { 
     e.preventDefault(); 
     $('.bottom').animate({ 
      bottom: "-100%", 
     }, 800); 
     $('.middle').animate({ 
      top: "0", 
     }, 800); 
    }); 

}); 

的CSS

html { 
    height:100%; 
    overflow:hidden; 
} 
body { 
    font: 20px/21px Helvetica, Arial, sans-serif; 
    color: #6c6c6c; 
    height:100%; 
} 
a { 
    color: #e74b34; 
    text-decoration: none; 
} 
a:hover { 
    color: #132c3b; 
    text-decoration:none; 
} 
section { 
    height:100%; 
    max-width:100%; 
    width:100%; 
    text-align: center; 
} 
.top { 
    background: #111; 
    position:absolute; 
    right:0; 
    left: 100%; 
    top:-100%; 
} 
.bottom { 
    background: #111; 
    position:absolute; 
    right:0; 
    left: 100%; 
    bottom:-100%; 
    background: #ccc; 
} 
.middle { 
    background: #000; 
    position: absolute; 
    left: 100%; 
    top:0; 
} 
.right { 
    background: #111; 
    position:absolute; 
    left:200%; 
    top:0; 
}