从JSFiddle复制代码
Copy the code from JSFiddle
很抱歉问了这个愚蠢的问题。。。我发现了其他类似的问题,但我想不通。
我不明白为什么它不起作用。我从复制代码http://jsfiddle.net/sB49B/21/
我认为问题应该是加载,但我不确定,因为我尝试的都不起作用。我决定将代码包括在:中
jQuery(document).ready(function($){
code javascript
)};
和:
$(document).ready(function(){
code javascript
)};
你有什么想法吗??!这是错误:未捕获的语法错误:意外的令牌)
这里的代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jsfiddle.net/sB49B/18/</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script type="text/javascript">
var oDebug = $('p#debug');
var oItemsContainer = $('ul#items');
$(window).scroll(function(e) {
var iScrollTop = $(window).scrollTop();
var iScrollPerItem = 200;
var aItems = oItemsContainer.children('li.item');
var iCurrentIndex = Math.floor(iScrollTop / iScrollPerItem);
var fOpacity= (iScrollTop % iScrollPerItem) / iScrollPerItem ;
aItems.filter(':lt(' + iCurrentIndex + ')').show();
aItems.filter(':gt(' + iCurrentIndex + ')').hide();
aItems.eq(iCurrentIndex).show().css('opacity', fOpacity);
});
</script>
<style type="text/css">
body { height:3000px; }
ul#items { width:200px; height:200px; position:fixed; top:10px; left:10px; }
ul#items li.item {background-color:#dddddd; display:block; height:100%; left:0; opacity:0; position:absolute; right:0; width:100%;}
p#debug {position:fixed; right:10px; text-align:right; top:10px; }
</style>
</head>
<body>
<p id="debug">n/a</p>
<ul id="items">
<li class="item item01">1</li>
<li class="item item02">2</li>
<li class="item item03">3</li>
<li class="item item04">4</li>
<li class="item item05">5</li>
<li class="item item06">6</li>
<li class="item item07">7</li>
<li class="item item08">8</li>
</ul>
</body>
</html>
是的,错误来了,因为你没有正确地关闭括号
$(document).ready(function(){
code javascript
)};
应该是
$(document).ready(function(){
code javascript
});
注意最后一行之间的差异
让我们读一下错误。。。意外的令牌)。。。嗯,也许是一个错位的)角色。
$(document).ready(function() {
var oDebug = $('p#debug');
var oItemsContainer = $('ul#items');
$(window).scroll(function(e) {
var iScrollTop = $(window).scrollTop();
var iScrollPerItem = 200;
var aItems = oItemsContainer.children('li.item');
var iCurrentIndex = Math.floor(iScrollTop / iScrollPerItem);
var fOpacity= (iScrollTop % iScrollPerItem) / iScrollPerItem ;
aItems.filter(':lt(' + iCurrentIndex + ')').show();
aItems.filter(':gt(' + iCurrentIndex + ')').hide();
aItems.eq(iCurrentIndex).show().css('opacity', fOpacity);
});
});
您的最后一行)};
错误。应该是});
,首先关闭的是function() {
的}
,然后是.ready(
的)
。
尝试这个
<script type="text/javascript">
$( document ).ready(function() {
console.log( "ready!" );
var oDebug = $('p#debug');
var oItemsContainer = $('ul#items');
$(window).scroll(function(e) {
var iScrollTop = $(window).scrollTop();
var iScrollPerItem = 200;
var aItems = oItemsContainer.children('li.item');
var iCurrentIndex = Math.floor(iScrollTop / iScrollPerItem);
var fOpacity= (iScrollTop % iScrollPerItem) / iScrollPerItem ;
aItems.filter(':lt(' + iCurrentIndex + ')').show();
aItems.filter(':gt(' + iCurrentIndex + ')').hide();
aItems.eq(iCurrentIndex).show().css('opacity', fOpacity);
});
}
</script>
并检查控制台,寻找"就绪!"如果您看到它,问题就出在逻辑
相关文章:
- 使用javascript代码将HTML元素复制到剪贴板
- 在jquery中复制特定的html代码
- 为什么这个文件上传拖放不起作用,我完全复制了 CodePen 代码
- 用于在表中添加行的Javascript代码将单元格中的数据复制到新行中
- 直接从代码笔复制的圆环图代码不起作用
- 将Excel值复制到javascript代码中
- 使用JavaScript从网页复制HTML代码或图像链接
- 如何让我的导航栏位于每个HTML页面的顶部(避免复制相同的代码)
- 阻止人们复制JavaScript代码
- 如何在 Chrome 控制台中复制多个元素的 HTML 代码
- 需要复制代码
- 即使我从另一个工作小提琴复制代码,JSFiddle 也不起作用
- 什么是不复制HTML页面和子页面上代码的现代方法
- jQuery - 重用代码而不复制它
- 将对象的孙属性复制到新创建的对象,而无需太多代码
- 适用于 ngRoute、ng-view 和代码复制的最佳实践
- zclip代码复制空白字符串,而不是文本字段的内容
- . getselection新代码复制,每次点击加一个
- 如何将“查看页面源代码”代码复制到新文件中
- AngularJS应用程序中的代码复制