我有5個div在我的html頁面和5個按鈕。我想通過自動滾動按鈕5點擊時獲得第5個div。但我不想使用的位置在X軸上滾動...我想要移動參考div div。所以我該怎麼做?幫我在jQuery或JavaScript。想要移動到不同的DIV按鈕點擊
2
A
回答
3
好心來看看下面的鏈接
我已經在那裏粘貼了代碼。
enter code here
enter code here
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript">
function scroll(val)
{
//alert(document.getElementById(val));
document.getElementById(val).click()
}
</script>
</head>
<body>
<div id="div1" style="height:200px">
The content of your div1 here.
</div>
<div id="div2" style="height:200px">
The content of your div2 here.
</div>
<div id="div3" style="height:200px">
The content of your div3 here.
</div>
<div id="div4" style="height:200px">
The content of your div4 here.
</div>
<div id="div5" style="height:200px">
The content of your div5 here.
</div>
<div style="display:none;">
<a href="#div1" id="id1">Link Text Here</a>
<a href="#div2" id="id2">Link Text Here</a>
<a href="#div3" id="id3">Link Text Here</a>
<a href="#div4" id="id4">Link Text Here</a>
<a href="#div5" id="id5">Link Text Here</a>
</div>
<input type="button" onclick="scroll('id1')" value="button1"></input>
<input type="button" onclick="scroll('id2')" value="button2"></input>
<input type="button" onclick="scroll('id3')" value="button3"></input>
<input type="button" onclick="scroll('id4')" value="button4"></input>
<input type="button" onclick="scroll('id5')" value="button5"></input>
</body>
</html>
enter code here
+1
http://stackoverflow.com/editing-help 。 – 2011-03-16 13:27:59
8
使用scrollTop()
和<div>
位置:
非動畫:
var $divs = $('div'),
$buttons = $('button');
$buttons.live('click', function()
{
var $this = $(this),
index = $buttons.index(this);
$(window).scrollTop($divs.eq(index).offset().top);
});
動畫:
var $divs = $('div'),
$buttons = $('button'),
$hb = $('html, body');
$buttons.live('click', function()
{
var $this = $(this),
index = $buttons.index(this);
$hb.animate({scrollTop: $divs.eq(index).offset().top + 'px'});
});
使用<div>
ID:
// snip...
$buttons.live('click', function()
{
var $this = $(this),
index = $buttons.index(this);
window.location.hash = $divs.eq(index).attr('id');
});
1
可能沒有確切的解決方案,但要實現這種解決方案的最簡單的方法是一樣的東西:
讓按鈕;
<Button><a href="#move_here" class="myClass"> Click It </a></Button>
,並要在Button Click
是移動DIV
;
<div>
<a name="move_here"></a>
...div content here...
</div>
我希望你已經注意到了move_here
。
相關問題
- 1. 想要點擊按鈕
- 2. 點擊按鈕應該移動到jquery中的不同標籤
- 3. 按鈕移動點擊
- 4. 等待按鈕點擊按鈕點擊移動按鈕到tkinter插槽
- 5. Div按鈕點擊不變
- 6. 我想要禁用點擊按鈕
- 7. 按鈕將不會點擊移動Safari
- 8. 移動菜單按鈕不可點擊
- 9. 點擊切換到不同的按鈕
- 10. 加載不同的HTML到相同的#Content DIV點擊不同的按鈕
- 11. 我想要執行不同的動作來點擊動態創建的不同按鈕
- 12. 我想自動點擊按鈕
- 13. 顯示上點擊相同的按鈕不同的div - 角JS
- 14. 移動Android按鈕間點擊活動
- 15. 移動鍵盤上的按鈕點擊
- 16. 滾動到按鈕上點擊類的div div
- 17. 不同的按鈕點擊按鈕外觀動畫 - Objective-C
- 18. 翻轉不同的div的EACK按鈕點擊不工作
- 19. Textarea不想清除(點擊按鈕時)
- 20. 我想只要在按鈕點擊擺動形式
- 21. 刪除點擊按鈕,按鈕的div點擊
- 22. iOS - 如何移動到不同的頁面上點擊一個按鈕
- 23. c#selenium點擊div按鈕
- 24. 按鈕點擊顯示div
- 25. 想要添加圖片到JPanel點擊按鈕
- 26. 移動按鈕不會收到點擊事件
- 27. 上點擊提交按鈕移動itsplace
- 28. 根據按鈕點擊移動圖像
- 29. 移動WebKit按鈕點擊虛擬類
- 30. Android圖像移動按鈕點擊
我想你需要[this]這樣的東西(http://djpate.com/2011/01/01/animated-scrollto-effect-jquery-plugin/) – add9 2011-03-16 13:06:53