[英]How do I use jQuery new advanced ticker to read text from text file?
I'm trying this code now in my website: 我正在我的网站上尝试此代码:
<script>
var file = "http://newsxpressmedia.com/files/theme/test.txt";
function getFile(){
$.get(file,function(txt){
var lines = txt.responseText.split("\n");
for (var i = 0, len = lines.length; i < len; i++) {
save(lines[i]);
<ul class="newsticker">lines[i]</ul>
}
});
}
</script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>
<script>
$('.newsticker').newsTicker({
row_height: 48,
max_rows: 2,
speed: 6000,
direction: 'up',
duration: 400,
autostart: 1,
pauseOnHover: 0
});
</script>
But I don't see anything. 但是我什么也没看到。 The text suppose to scroll up.
文本应该向上滚动。
In the original the code was: 原始代码是:
<ul class="newsticker">
<li>Etiam imperdiet volutpat libero eu tristique.</li>
<li>Curabitur porttitor ante eget hendrerit adipiscing.</li>
<li>Praesent ornare nisl lorem, ut condimentum lectus gravida ut.</li>
<li>Nunc ultrices tortor eu massa placerat posuere.</li>
</ul>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>
<script>
$('.newsticker').newsTicker({
row_height: 48,
max_rows: 2,
speed: 6000,
direction: 'up',
duration: 400,
autostart: 1,
pauseOnHover: 0
});
</script>
What am I doing wrong ? 我究竟做错了什么 ? I checked I the file test.txt exist and I can read it but the code :
我检查了文件test.txt是否存在,并且可以读取,但代码如下:
<script>
var file = "http://newsxpressmedia.com/files/theme/test.txt";
function getFile(){
$.get(file,function(txt){
var lines = txt.responseText.split("\n");
for (var i = 0, len = lines.length; i < len; i++) {
save(lines[i]);
<ul class="newsticker">lines[i]</ul>
}
});
}
</script>
Is not working I don't see anything. 没有工作,我什么也看不到。 Tried to add in the FOR LOOP the line:
试图在FOR LOOP中添加以下行:
<ul class="newsticker">lines[i]</ul>
But I guess it's wrong. 但是我想这是错误的。
EDIT** 编辑**
The code is now look like this: 现在的代码如下所示:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://newsxpressmedia.com/files/theme/jquery.newsTicker.js"></script>
<script>
$(function() {
var file = "http://newsxpressmedia.com/files/theme/test.txt";
$.get(file, function (txt) {
var lines = txt.responseText.split("\n");
$ul = $('<ul class="newsticker" />');
for (var i = 0, len = lines.length; i < len; i++) {
//save(lines[i]); // not sure what this does
$ul.append('<li>' + lines[i] + '</li>');
}
$ul.appendTo('body').newsTicker({
row_height: 48,
max_rows: 2,
speed: 6000,
direction: 'up',
duration: 400,
autostart: 1,
pauseOnHover: 0
});
});
});
</script>
But it does nothing i don't see any text at all. 但是它什么也没做,我根本看不到任何文本。
EDIT** 编辑**
Opend the console dev on my website at: http://newsxpressmedia.com/ And i see this text in the console: 在我的网站上打开控制台开发者: http ://newsxpressmedia.com/,我在控制台中看到以下文本:
6 Consider using 'dppx' units instead of 'dpi', as in CSS 'dpi' means dots-per-CSS-inch, not dots-per-physical-inch, so does not correspond to the actual 'dpi' of a screen. 6考虑使用“ dppx”单位代替“ dpi”,因为在CSS中,“ dpi”表示每CSS英寸的点数,而不是每物理英寸的点数,因此不对应于屏幕的实际“ dpi” 。 In media query expression: only screen and (-webkit-min-device-pixel-ratio: 2), not all, not all, not all, only screen and (min-resolution: 192dpi), only screen and (min-resolution: 2dppx) (index):1 Uncaught TypeError: Cannot call method 'split' of undefined (index):101 event.returnValue is deprecated.
在媒体查询表达式中:仅屏幕和(-webkit-min-device-pixel-ratio:2),不是全部,不是全部,不是全部,仅屏幕和(min分辨率:192dpi),仅屏幕和(min分辨率:2dppx)(索引):1未捕获的TypeError:无法调用未定义(索引):101 event的方法'split'.returnValue已弃用。 Please use the standard event.preventDefault() instead.
请改用标准event.preventDefault()。
You have two issues. 你有两个问题。 The first is that you need to create your
li
elements and append them to the dom. 首先是您需要创建
li
元素并将其附加到dom。 The second is that you aren't waiting for the ajax call to finish before setting up the newsticker plugin. 第二个是在设置newsticker插件之前,您无需等待ajax调用完成。 I also don't see a reason to have the
getFile
function: 我也看不到具有
getFile
函数的原因:
$(function() {
var file = "http://newsxpressmedia.com/files/theme/test.txt";
$.get(file, function (txt) {
var lines = txt.responseText.split("\n");
$ul = $('<ul class="newsticker" />');
for (var i = 0, len = lines.length; i < len; i++) {
//save(lines[i]); // not sure what this does
$ul.append('<li>' + lines[i] + '</li>');
}
$ul.appendTo('body').newsTicker({
row_height: 48,
max_rows: 2,
speed: 6000,
direction: 'up',
duration: 400,
autostart: 1,
pauseOnHover: 0
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.