2013-12-10 72 views
1

我的頁面由2個彼此相鄰的div組成。鏈接到div內的更改位置

說左邊的div是一本有不同章節的書。

我想我在正確的格鏈接到移動DIV中的內容有在頂部點擊章(基本上向下滾動到這一章。

有可能是爲了這個,我」一個簡單的答案中號失蹤,

任何幫助將是巨大的

+1

你必須證明你已經到目前爲止已經試過你的工作,看到有巨大的事情處理這些類型的問題(HTTP [**是否應堆棧溢出獎勵努力**?]://meta.stackexchange .COM /問題/ 210840 /應堆棧溢出待授牌,作爲換工作?CB = 1)。所以不要歸入這個類別。 – Praveen

+0

只是想快速回答,所以沒有感到需要。它在我的問題中明確指出我想要什麼,所以知道html/css的人可以在30秒內回答它。 – BigJayMalcolm

+0

但是如果沒有代碼,我們將無法看到您嘗試過的內容,然後我們可能會回答您已經嘗試過的內容。也許你在代碼中有一些東西,然後我們不知道這些。 –

回答

1

試試這個:

<div id="text"> 
    <h1 id="chapterone">Chapter one</h1> 
    <p>The text of chapter 1</p> 
    <h1 id="chaptertwo">Chapter two</h1> 
    <p>The text of chapter 2</p> 
    <h1 id="chapterthree">Chapter three</h1> 
    <p>The text of chapter 3</p> 
</div> 
<div id="links"> 
    <a href="#chapterone">Chapter one</a> 
    <a href="#chaptertwo">Chapter two</a> 
    <a href="#chapterthree">Chapter three</a> 
</div> 

如果您使用ARW iFrame中看一看到jQuery ScrollTo

+0

完美的工作,謝謝! – BigJayMalcolm

+0

@BigJayMalcolm愉快,並記得勾選它。 –

+0

是啊,只是等待2分鐘,直到我可以:) – BigJayMalcolm

0

最簡單的方法就是使用href。這隻有在你使用HTML構建「書」時纔有用,它不是圖像,PDF或其他內容。

給每個章節的標題,如「CH1」,「C」等一個唯一的ID

然後設置HREF鏈接章,如果1

<div id="left"> 
    <h1 id="ch1"> 
    <h2 id="ch2"> 
    #etc 
</div> 
<div id="right"> 
    <a href="#ch1">Chapter 1</a> 
    <a href = "#ch2">Chapter 2</a> 
    #etc 
</div> 

提醒你這只是作品「書「是HTML。如果它是iframed或是圖像,然後查看jQuery插件Scrollto,它將允許您爲要滾動到的每個元素設置滾動高度(以像素爲單位)。

http://flesler.blogspot.com/2007/10/jqueryscrollto.html

0

您需要使用href,並使其發揮作用。章節標題的hrefid應該相同。這樣它將導航到特定的標題。

<div> <!-- for links--> 
<a href="#firstChapter">FirstChapter </a> 
<a href="#secondChapter">Second Chapter </a> 
<a href="#lastChapter">Last Chapter </a> 
</div> 
<div> <!-- for Chapters --> 
<h1 id="firstChapter"> Chapter 1</h1> 
<p>Content of chapter </p> 
<h1 id="secondChapter"> Chapter 2</h1> 
<p>Content of chapter </p> 
<h1 id="lastChapter"> Chapter 10</h1> 
<p>Content of chapter </p> 
</div>