嗯,这是vscroller.js文件插件..我已经修改了一下,以满足我的需求
(function ($) {
$.fn.extend({
vscroller: function (options) {
var settings = $.extend({ speed: 2000, stay: 3000, newsfeed: '', cache: true }, options);
return this.each(function() {
var interval = null;
var mouseIn = false;
var totalElements;
var isScrolling = false;
var h;
var t;
var wrapper = $(this).addClass('news-wrapper');
if (settings.newsfeed == '') { alert('No XML file specified'); return; }
$.ajax({
url: settings.newsfeed,
type: 'GET',
dataType: 'xml',
cache: settings.cache,
success: function (xml) {
//if there are news headlines then build the html
var contentWrapper = $('<div/>').addClass('news-contents-wrapper');
var newsHeader = $('<div/>').addClass('news-header');
var newsContents = $('<div/>').addClass('news-contents');
wrapper.append(contentWrapper);
contentWrapper.append(newsHeader);
contentWrapper.append(newsContents);
newsHeader.html($(xml).find('newslist').attr('title'));
var i = 0;
totalElements = $(xml).find('news').length;
$(xml).find('news').each(function() {
var news = $('<div/>').addClass('news');
newsContents.append(news);
var description = $('<div/>').addClass('description');
news.append(description);
var url = $(this).attr('url');
var htext = $(this).find('headline').text();
description.append($('<span>').html("<img src='home/images/icons/bullet.png' /> <a style='color:#ffffff' href='" + url + "'>" + htext + "</a>"));
var newsText = $(this).find('detail').text();
if (newsText.length > 80) {
newsText = newsText.substr(0, 80) + "...";
}
description.append($('<div/>').addClass('detail').html(newsText));
});
h = parseFloat($('.news:eq(0)').outerHeight());
$('.news', wrapper).each(function() {
$(this).css({ top: i++ *20 });
});
t = (totalElements - 1) * h;
newsContents.mouseenter(function() {
mouseIn = true;
if (!isScrolling) {
$('.news').stop(true, false);
clearTimeout(interval);
}
});
newsContents.mouseleave(function() {
mouseIn = false;
interval = setTimeout(scroll, settings.stay);
});
interval = setTimeout(scroll, 1);
}
});
//$.get(settings.newsfeed,);
function scroll() {
if (!mouseIn && !isScrolling) {
isScrolling = true;
$('.news:eq(0)').stop(true, false).animate({ top: -50 }, settings.speed, function() {
clearTimeout(interval);
var current = $('.news:eq(0)').clone(true);
current.css({ top: 40 });
$('.news-contents').append(current);
$('.news:eq(0)').remove();
isScrolling = false;
interval = setTimeout(scroll, settings.stay);
});
$('.news:gt(0)').stop(true, false).animate({ top: '-=' + 20 }, settings.speed);
}
}
});
}
});
})(jQuery);
相应的CSS文件
.news-wrapper
{
}
.news-wrapper .news-contents-wrapper
{
width: 200px;
margin: auto;
height: 20px;
}
.news-wrapper .news-contents
{
overflow: hidden;
position: relative;
z-index: 998;
height: 200px;
right:8px;
}
.news-wrapper .news
{
width: 100%;
height: 5px;
color: #6a6a6a;
position: absolute;
}
.news-wrapper .news-header
{
color: White;
height: 20px;
font-weight: bold;
font-size: 14px;
padding-top: 12px;
padding-left: 10px;
padding-bottom: 20px;
}
h1
{
color: White;
font-size: 14px;
}
.clear
{
clear: both;
}
.history
{
padding-top: 14px;
float: left;
width: 26%;
padding-left: 32px;
}
.description
{
float: left;
width: 64%;
padding: 4px;
}
.description .detail
{
font-size: 12px;
overflow: hidden;
color:#B1B1B1;
}
.elipses, .day, .month
{
display: block;
height: 10px;
}
.day, .month
{
padding-top: 6px;
}
h1 a, h1 a:active, h1 a:visited
{
text-decoration: none;
color:White;
}
h1 a:hover
{
text-decoration: underline;
color:White;
}
与详细信息的XML文件,我滚动
<?xml version="1.0" encoding="utf-8" ?>
<newslist title="Quick Links">
<news url="#" date="">
<headline>Details 1</headline>
</news>
<news url="#" date="">
<headline>Details 1</headline>
</news>
<news url="#" date="">
<headline>Details 1</headline>
</news>
</newslist>
我的HTML文件
需要0
<span class="news-wrapper" id="vscroller" style=" background:rgba(1,102,220,0.3);left: 20px;top:8px;position:relative;float: left; top:228px;height:95px;width: 150px; padding:0 2% 0 2%;">
</span>
终于JS
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('#vscroller').vscroller({ newsfeed: 'home/js/news.xml' });
});
</script>
你有没有考虑使内容滚动?然后你可以告诉jQuery自动向下滚动。 – rybo111
我最近遇到这个名为vscrolller.js的插件..如果你有兴趣我可以帮你给我使用的代码 –
@ rybo111你的意思是'style =“overflow:scroll''?然后让jquery自动向下滚动? –