jQuery悬停时无限/连续滚动
jQuery infinite/continuous scrolling on hover
我似乎在边缘滚动解决方案附近悬停时遇到了一些问题,我已经实现了拖动滚动解决方案。
这是我的代码:
演示1(当前页面):http://jsfiddle.net/SO_AMK/FdLZJ/
演示2(我尝试过的):http://jsfiddle.net/SO_AMK/8CCeA/
HTML摘录:
<section class="row">
<div class="scroll-left" style="opacity: 0;"></div>
<div class="row-scroll">
<div class="tile">
<img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
<title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
</div>
.....
<div class="tile">
<img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
<title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
</div>
</div>
<div class="scroll-right" style="opacity: 0;"></div>
</section>
<section class="row">
<div class="scroll-left" style="opacity: 0;"></div>
<div class="row-scroll">
<div class="tile">
<img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
<title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
</div>
.....
<div class="tile">
<img class="tile-image" src="http://cache.gawker.com/assets/images/lifehacker/2011/08/1030-macpack-notational-velocity.jpg" />
<title class="tile-title">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor...</title>
</div>
</div>
<div class="scroll-right" style="opacity: 0;"></div>
</section>
jQuery:
$(document).ready(function () {
var pos = 5;
$.fn.loopingScroll = function (direction, scrollElement) {
if (direction == "right") {
pos+=5;
}
else if (direction == "left") {
pos-=5;
}
$(scrollElement).parent().scrollLeft($(scrollElement).parent().data('scrollLeft') + pos);
return this;
}
$(".scroll-left").hover(function(){
scrollLeftLoop = setInterval(function(){
$(this).loopingScroll("left", this);
}, 25);
$(this).fadeIn('fast');
}, function() { clearInterval(scrollLeftLoop); $(this).fadeOut('fast'); });
$(".scroll-right").hover(function(){
scrollRightLoop = setInterval(function(){
$(this).loopingScroll("right", this);
}, 25);
$(this).fadeIn('fast');
}, function() { clearInterval(scrollRightLoop); $(this).fadeOut('fast'); });
});
它应该是一个Pulse替代品/WebApp,因此设计(我正在设计字体)。
有什么想法吗?
提前谢谢。
好吧,经过一番思考,我想出了这个:
$(".scroll-left").hover(function() {
$(this).parent().animate({scrollLeft: 0}, 7000);
$(this).fadeIn('fast');
}, function() {
$(this).parent().stop();
$(this).fadeOut('fast');
});
$(".scroll-right").hover(function() {
$(this).parent().animate({scrollLeft: $(this).siblings(".row-scroll").width()}, 7000);
$(this).fadeIn('fast');
}, function() {
$(this).parent().stop();
$(this).fadeOut('fast');
});
它基本上使用scrollLeft
函数,并实时计算滚动元素的宽度,用作滚动到值。下面是一个演示此代码的JSFiddle。
我希望有人对此有用,我正在适当地重命名这个问题。
我知道为时已晚,但如果其他人需要帮助,他们可以找到解决方案。尝试动画循环
function loopl(){
$('.mCSB_container').animate({ "left": "+=80px" }, "800", 'linear', loopl );
}
function loopr(){
$('.mCSB_container').animate({ "left": "-=80px" }, "800", 'linear', loopr );
}
function stop(){
$('.mCSB_container').stop();
}
$( "#left" ).hover(loopl, stop);
$( "#right" ).hover(loopr, stop);
相关文章:
- 如何做javascript连续滚动-自动加载
- 整页.js使用连续滚动或循环时禁用 moveSectionUp
- jQuery悬停时无限/连续滚动
- 不连续滚动-检测用户是否停止滚动
- 连续滚动背景
- 在 iOS Chrome 中获取连续滚动事件
- 连续的 html 页面滚动
- 连续滚动.AJAX, PHP, JAVASCRIPT, MYSQL.
- Twitter Bootstrap Carousel - 如何实现连续慢速滚动
- 连续图像垂直滚动条
- 使用javascript进行连续滚动
- 使用jquery在同一方向上连续滚动滑块
- 脚本连续滚动到页面底部
- 使用javascript的连续滚动页面
- 自定义按钮,以取代浏览器滚动-保持和连续滚动
- 连续滚动计时器-避免跳跃
- Jquery插件与连续滚动像新闻票
- 在HTML / Bootstrap中连续滚动图像
- 使用 jquery 航点连续滚动
- 帮助修改我的自定义JQuery滑块,以允许连续滚动