我有一個jQuery的難題。可以有人幫我選擇適當的div來滾動。現在它適用於第一個但其他人只是不工作。這裏是代碼:https://jsfiddle.net/fwm4ot69/在同一類中選擇div
這裏是JS代碼
$(document).ready(function() {
//hide answers or hide in css
$('.acc_content').hide();
$('.acctitle').click(function() {
//show this answer
$(this).next().slideToggle('1000');
//Hide the other panels
$(".acc_content").not($(this).next()).slideUp('fast');
$.scrollTo($(this), 1000);
});
});
這是我的HTML
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script src="//code.jquery.com/jquery-1.12.0.min.js">
</script>
<div class="accordion">
<div class="acctitle">
<h3>What is This?</h3>
</div>
<div class="acc_content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text
ever since the 1500s, when an unknown printer took a galley of type
and scrambled it to make a type specimen book. It has survived not
only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="acctitle">
<h3>What is This?</h3>
</div>
<div class="acc_content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text
ever since the 1500s, when an unknown printer took a galley of type
and scrambled it to make a type specimen book. It has survived not
only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="acctitle">
<h3>What is This?</h3>
</div>
<div class="acc_content">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been the industry's standard dummy text
ever since the 1500s, when an unknown printer took a galley of type
and scrambled it to make a type specimen book. It has survived not
only five centuries, but also the leap into electronic typesetting,
remaining essentially unchanged. It was popularised in the 1960s
with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</body>
</html>
What can i do to make the screen start on the selected question, esp on a mobile device?
THanks
首先,指定您如何訪問一個選定的頁面......如www.domain.com/question1或www.domain.com?q = 1或其他。然後顯示你如何生成HTML。你可以給任何元素一個ID或類,所以通過get vars或uri段來分配一個類是合乎邏輯的,然後在js中你只需檢查該元素的類$('。selected').length,然後滾動到它在加載$ .scrollTo($('。selected')。offset()。top,1000);這將有助於看到你的HTML。小提琴在這裏沒問題,所以編輯可能沒有必要,但不是每個人都會按照鏈接 –
我試圖啓動頁面上點擊的問題 – user3750366
頁面不點擊任何東西開始。他們必須知道選擇什麼東西,因此入站鏈接必須具有某種標識符。 ?q = 1,/ question/1,#question1等等。你現在怎麼做? –