2013-12-17 20 views

回答

1

嗯,我明白了。嘗試

<div class="faque_question_table"> 
    <ul> 
     <li id="q1"><a class="qli" href="answer.html?#ans1">Create new course</a></li> 
     <li id="q2"><a class="qli" href="answer.html?#ans2">Set privacy and assign users</a>/li> 
     <li id="q3"><a class="qli" href="answer.html?#ans3">View course.</a></li> 
     <li id="q4"><a class="qli" href="answer.html?#ans4">Edit and delete course.</a></li> 
     <li id="q5"><a class="qli" href="answer.html?#ans5">Add thumbnail representation.</a></li> 
    </ul> 

</div> 
<!-- After some code your answer.html--> 
<div class="help_sub_content" id='ans1'> Your answer 1</div> 
<div class="help_sub_content" id='ans2'> Your answer 1</div> 
<div class="help_sub_content" id='ans3'> Your answer 1</div> 
<div class="help_sub_content" id='ans4'> Your answer 1</div> 

然後腳本

<script> 
    $(document).ready(function() 
    { 

      $(".qli").click(function(){ 
    $('html, body').animate({'scrollTop' : $($(this).attr('href')).offset().top},1000) //Will maybe be $(window) instead of html,body. 
    return false; 
      }); 
}); 
</script> 
+1

@Blessing你可以選擇你正確的答案。無論如何感謝您提出編輯。 – 2013-12-17 06:26:58

+0

我喜歡你的答案。我們來修復兩件事。 1.頁面重定向並滾動到正確的位置,但在一段時間後滾動。可能頁面還沒有完成加載,但我有dom準備好的功能。 2.我們使用類而不是ID,以便可以在所有頁面中引用答案。那麼你怎麼寫這個? 'answer.html?class' – Relm

0

id="some-id"字的容器上,然後把標識上的網址:

http://example.com/faq#some-id 

如果你想要一些奇特的滾動發生,並在字褪色,那麼你可以使用像jQuery的。有相當多的插件做花式滾動。淡入淡出可以在不使用插件的情況下完成。

1

你可以執行該如此輕易mate.Just嘗試下面的腳本,其相當useful.I做了fiddle適合您purpose.Since你需要一旦點擊鏈接轉到單詞通過identifier word# symbol之後的網址或使用javascript獲得該單詞split

代碼

$('.disclosure').highlight('Test'); 
$('html, body').animate({ 
     scrollTop: $(".highlight").offset().top 
    }, 1500); 

包含這個腳本

http://johannburkard.de/resources/Johann/jquery.highlight-4.js

小提琴

http://jsfiddle.net/HehgB/

無需任何外部插件

var src_str = $(".disclosure").html(); 
var term = "massa"; 
term = term.replace(/(\s+)/,"(<[^>]+>)*$1(<[^>]+>)*"); 
var pattern = new RegExp("("+term+")", "i"); 

src_str = src_str.replace(pattern, "<mark>$1</mark>"); 
src_str = src_str.replace(/(<mark>[^<>]*)((<[^>]+>)+)([^<>]*<\/mark>)/,"$1</mark>$2<mark>$4"); 
$(".disclosure").html(src_str); 
$('html, body').animate({ 
     scrollTop: $("mark").offset().top 
    }, 1500); 

小提琴

http://jsfiddle.net/4tZ55/

+0

我會盡可能地避免任何額外的js,我想要的只是沒有插件的滾動和突出顯示。 – Relm

+0

我已更新答案隊友.. – Outlooker

相關問題