我的實際問題是我有三個段落,所以每個都是不同的高度。我爲第一段應用了slideUp()效果,爲第二段應用了slideDown()效果。並將按鈕放在第一段和第二段之間。如果點擊按鈕,第一段將滑動,第二段將滑動。該行動完美,但我需要如果第一段向上滑動它滾動到第三段。我如何在第二段中停止它。在特定元素停止jQuery slideUp()
1
A
回答
1
我會建議使用下面的代碼:
$(document).ready(function() {
$("#show").click(function() {
$("body").animate({ scrollTop: 0 });
$(".one").slideUp();
});
});
更新
更好的解決方案:
$(document).ready(function() {
$("#show").click(function() {
$(window).scrollTop(0)
$(".one").slideUp();
});
});
0
移動或調整大小的桌面瀏覽器大小試試這個移動寬度
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#show").click(function(){
$(".two").show("slow");
$(".one").hide("slow");
});
});
</script>
</head>
<body>
<p class="one" style="color:blue;">If you click on the "Hide" button, I will disappear.If you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I wilthe "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will dthe "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will dthe "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will dl disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappear</p>
<button id="show" >Show</button>
<div class="two" style="color:green;">rIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on t</div>
<p class="three">
utton, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you c
</p>
</body>
</html>
0
您可以嘗試scrollTop
$(document).ready(function() {
$("#show").click(function() {
$(".two").show("slow");
$(".one").hide("slow", function(){
\t \t $('html, body').animate({
scrollTop: $(".two").offset().top
\t }, 500);
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<p class="one" style="color:blue;">If you click on the "Hide" button, I will disappear.If you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I wilthe "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will dthe "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will dthe "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will dl disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappear</p>
<button id="show" >Show</button>
<div class="two" style="color:green;">rIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on t</div>
<p class="three">
utton, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you click on the "Hide" button, I will disappearIf you c
</p>
+0
它似乎不是一個優雅的解決方案,它滾動到底部然後到頂部。 –
相關問題
- 1. jQuery slideUp顯示元素
- 2. JQuery停止元素從
- 3. 停止jQuery Mouseleave事件當進入另一個特定元素
- 4. jQuery - 計數元素,直到您到達特定元素並停止計數
- 5. 多個元素的jQuery動畫/ slideUp/slideDown
- 6. jQuery slideUp顯示元素而不隱藏
- 7. jQuery的預防停止()從給定高度元素
- 8. 從脈動jquery停止元素
- 9. jquery select特定元素
- 10. Jquery目標特定元素
- 11. Slidingown元素和slideUp其他
- 12. 停止特定的jQuery動畫
- 13. 在目標元素上方的固定像素處停止jquery滾動
- 14. 防止CSS:懸停元素
- 15. Joint.js:防止特定元素被鏈接
- 16. 解除綁定特定的jQuery元素
- 17. 當調用Show()時,停止JQuery元素在錯誤的位置顯示元素?
- 18. jQuery獨特元素
- 19. 如何使某個元素在特定點之後停止滾動?
- 20. 在IE上停止BGSOUND元素?
- 21. Akka流在一個元素後停止
- 22. 停止在不同元素上傳播
- 23. JQuery:在到達元素之前停止滾動
- 24. 停止在子元素上運行的jQuery切換功能
- 25. 如何停止元素的resizable屬性在jQuery UI的
- 26. 使用jQuery查找特定元素
- 27. Jquery爲特定元素禁用主題
- 28. jquery過濾掉特定元素
- 29. 具有特定ID的Jquery .load元素?
- 30. 使用jQuery導航到特定元素
你能創建一個類似[這裏演示(http://www.jsfiddle.net)? – divy3993
[Jsfiddle Demo](http://jsfiddle.net/hxgyz2cr/) –
好的。其實它不會滾動到第三個。當你刪除第一段時,首先佔用的空間減少到零。 – divy3993