使用 jQuery 滚动窗格
scrolling pane using jquery
<script language="javascript">
$(document).ready(function($) {
var methods = {
init: function(options) {
this.children(':first').stop();
this.marquee('play');
},
play: function() {
var marquee = this,
pixelsPerSecond = 100,
firstChild = this.children(':first'),
totalHeight = 0,
difference,
duration;
// Find the total height of the children by adding each child's height:
this.children().each(function(index, element) {
totalHeight += $(element).innerHeight();
});
// The distance the divs have to travel to reach -1 * totalHeight:
difference = totalHeight + parseInt(firstChild.css('margin-top'), 10);
// The duration of the animation needed to get the correct speed:
duration = (difference/pixelsPerSecond) * 1000;
// Animate the first child's margin-top to -1 * totalHeight:
firstChild.animate(
{ 'margin-top': -1 * totalHeight },
duration,
'linear',
function() {
// Move the first child back down (below the container):
firstChild.css('margin-top', marquee.innerHeight());
// Restart whole process... :)
marquee.marquee('play');
}
);
},
pause: function() {
this.children(':first').stop();
}
};
$.fn.marquee = function(method) {
// Method calling logic
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.marquee');
}
};
})(jQuery);
var marquee = $('#marquee');
marquee.marquee();
marquee.hover(function() {
marquee.marquee('pause');
}, function() {
marquee.marquee('play');
});
</script>
<style type="text/css">
#marquee {
margin:inherit;
width:auto;
height:inherit
}
</style>
我想使用 jquery 创建一个滚动条,但我失败了。上面的代码是我用来向上滚动我的项目的选框。我按如下方式使用它,
<html>
<body>
<div class="content">
<div id="marquee">
<ul>
<li>...</li>
....
</ul>
</div>
</div></body>
</html>
但它根本不滚动,我使用的代码中是否有不正确的内容,您可以为我找到?
不确定边距顶部是否应该为此工作。尝试对持有人块(选框(使用 position:relative 和 position:absolute 表示内容 (ul(。并更新顶部而不是顶部边距。但在这种情况下,您可能需要为选框div 指定高度和溢出:隐藏。另一种选择是为选框设置高度和 oveflow:隐藏,但保留位置默认值。并使用scrollTop或一些类似的jquery函数滚动内容。
相关文章:
- Image赢得't隐藏在滚动jQuery上
- 无限滚动jquery不起作用
- 如何在水平滚动 Jquery 上实现延迟加载
- 在Firefox中快速滚动jQuery
- 触摸板滚动jQuery的问题
- 无限滚动jquery插件不起作用
- 如何仅在每次单击可滚动(jquery工具)中的导航按钮时加载图像,而不是一次加载所有图像
- 停止页面滚动 jquery
- 自动滚动 Jquery
- 动画滚动jquery不工作
- 导航锚点不'滚动jQuery时不能正确应用活动类
- 平滑滚动jquery插件在刷新时重置滚动起点.有办法解决这个问题吗
- 当用户滚动jquery时,停止ScrollTop功能
- 阻止自动向下滚动Jquery
- 水平滚动jQuery固定导航
- 平滑滚动jquery+修复导航错误
- 使用淡入淡出滚动jQuery效果的2列浮动画廊
- 无限滚动jQuery &Laravel 5分页
- 防止窗口滚动jquery
- 返回页首滚动jquery在chrome中不起作用.为什么?它在firefox中运行良好