有時候軟件安裝程序會強制您在啓用「我同意」框之前滾動到EULA的末尾。我怎樣才能在網頁上產生相同的效果?Javascript滾動到結尾
3
A
回答
5
<html>
<head>
<script type="text/javascript">
function setupPage() {
var agreement = document.getElementById("agreetext");
var visibleHeight = agreement.clientHeight;
var scrollableHeight = agreement.scrollHeight;
if (scrollableHeight > visibleHeight) {
var checkbox = document.getElementById("agreebox");
checkbox.checked=false;
checkbox.disabled=true;
agreement.onscroll = handleScroll;
}
}
function handleScroll() {
var agreement = document.getElementById("agreetext");
var visibleHeight = agreement.clientHeight;
var scrollableHeight = agreement.scrollHeight;
var position = agreement.scrollTop;
if (position + visibleHeight == scrollableHeight) {
document.getElementById("agreebox").disabled=false;
}
}
</script>
</head>
<body>
<form>
<textarea id="agreetext" rows="8" cols="40">Long agreement</textarea>
<br/><br/>
<input type="checkbox" id="agreebox" value="true"/> <label id="agreelabel" for="agreebox">I agree</label>
<br/><br/>
<input type="submit" value="Continue"/>
</form>
<script type="text/javascript">
// We put this at the end of the page rather than in an document.onload
// because the document.onload event doesn't fire until all images have loaded.
setupPage();
</script>
</body>
</html>
1
的代碼出色的一點,如果你也想在標籤中改變顏色旁邊的複選框,只需修改代碼如下:
function setupPage() {
var agreement = document.getElementById("agreetext");
var visibleHeight = agreement.clientHeight;
var scrollableHeight = agreement.scrollHeight;
if (scrollableHeight > visibleHeight) {
var checkbox = document.getElementById("agreebox");
checkbox.checked=false;
checkbox.disabled=true;
document.getElementById("agreelabel").style.color = "#777";
agreement.onscroll = handleScroll;
}
}
function handleScroll() {
var agreement = document.getElementById("agreetext");
var visibleHeight = agreement.clientHeight;
var scrollableHeight = agreement.scrollHeight;
var position = agreement.scrollTop;
if (position + visibleHeight == scrollableHeight) {
document.getElementById("agreebox").disabled=false;
document.getElementById("agreelabel").style.color = "black";
}
}
1
我用只讀文本區域來顯示我的許可協議。請注意,如果許可證協議文本不足以使textarea顯示滾動條,則此代碼將不起作用。
$(function() {
var serviceAgreementScrolled = false;
$('#service-agreement-textarea').scroll(
function() {
if (this.scrollTop + $(this).height() + 30 >= this.scrollHeight) {
serviceAgreementScrolled = true;
}
}
);
$('#accept-service-agreement-checkbox').change(
function() {
if ($(this).is(':checked') && !serviceAgreementScrolled) {
alert('Please scroll to read the rest of the service agreement.');
$(this).prop('checked', false);
}
}
);
});
<textarea id="service-agreement-textarea" readonly="readonly">Long long text here</textarea>
<label>
<input type="checkbox" id="accept-service-agreement-checkbox" />
I accept the terms of the service agreement
</label>
相關問題
- 1. Espresso:Recyclerview滾動到結尾
- 2. Espresso Recyclerview滾動到結尾
- 3. 如何滾動到System.Windows.Forms.WebBrowser的結尾?
- 4. Android:Seekbar不會一直滾動到結尾
- 5. 在列表結尾滾動到頂部
- 6. WordPress滾動抖動滾動到結尾時
- 7. fire(call)方法,當滾動查看器滾動到其結尾
- 8. 如何允許滾動NSTextView的結尾?
- 9. 在IDEA中滾動過去的結尾
- 10. 如何在到達頁面結尾時滾動固定div 200px(滾動時)?
- 11. 自動滾動到NSTextView的末尾
- 12. 動態滾動到頁面末尾
- 13. 的Javascript滾動到結果的底部滾動頁面
- 14. 單行wpf文本框水平滾動到結尾
- 15. 確定文本框何時滾動到結尾
- 16. Android WebView:如何滾動到文檔的結尾?
- 17. 在到達結尾之前使文本輸入滾動
- 18. Listview在到達結尾後反向滾動?
- 19. 以編程方式滾動到屏幕結尾
- 20. 我如何讓一個div滾動到其結尾,Y軸
- 21. 使用NetworkImageView滾動到列表結尾Volley
- 22. 獲取SWT StyledText小部件始終滾動到其結尾
- 23. 如何知道網格視圖是否滾動到結尾
- 24. 無法滾動到TreeView的結尾PyGTK/GTK
- 25. div滾動到JavaScript
- 26. 滾動到一行的末尾WPF TextBox
- 27. Windows Phone ListBox滾動到末尾
- 28. 滾動到UITextView的文本末尾
- 29. HorizontalScrollView,自動滾動以動畫結尾
- 30. QListWidget自動移動到列表結尾
爲什麼你要這麼做?沒有冒犯,但這是最令人討厭和無用的'功能'! – 2008-11-25 17:14:25