我需要这个自动滚动的帮助。当鼠标悬停在它上面时,请帮我暂停滚动。谢谢。
/*scroll view*/
$('.scroll').wrap('<div class="scroll-group"></div>');
$('.scroll').css({
'overflow': 'hidden',
height: 'auto'
});
$('.scroll-group').append($('.scroll').clone());
$('.scroll-group').wrap('<div class="scroll-wrap"></div>');
$('.scroll-wrap').css({
'overflow': 'hidden'
});
/*animate*/
var targetY = $('.scroll').eq(0).outerHeight();
var scroll = function(resetY) {
//animate 기본 동작 변형 "swing" -> "linear"
$('.scroll-group').animate({
top: targetY * -1 + 'px'
}, 6000, "linear", function() {
$('.scroll-group').css({
top: 0
});
scroll();
});
}
scroll();
.scroll-wrap,
.scroll {
width: 100px;
height: 102px;
overflow-y: scroll;
margin: 0;
position: relative
}
.scroll-group {
position: absolute;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="scroll">content-1<br />content-2<br />content-3<br />content-4<br />content-5<br />content-6<br />content-7<br />content-8<br />content-9<br />content-10<br /></p>
答案 0 :(得分:1)
请使用此fiddle。
我已将hover
和mouseleave
功能分别添加到pause
和resume
滚动。
/*scroll view*/
$('.scroll').wrap('<div class="scroll-group"></div>');
$('.scroll').css({'overflow':'hidden',height:'auto'});
$('.scroll-group').append($('.scroll').clone());
$('.scroll-group').wrap('<div class="scroll-wrap"></div>');
$('.scroll-wrap').css({'overflow':'hidden'});
/*animate*/
var targetY = $('.scroll').eq(0).outerHeight();
var scroll = function(resetY){
//animate 기본 동작 변형 "swing" -> "linear"
$('.scroll-group').animate({top:targetY*-1+'px'},6000,"linear", function(){
$('.scroll-group').css({top:0});
scroll();
});
$('.scroll-group').hover(function() { //mouseenter
$('.scroll-group').stop(true, false);
});
$(".scroll-group").mouseleave(function(){
scroll();
});
}
scroll();
&#13;
.scroll-wrap,.scroll {width:100px; height:102px;overflow-y:scroll; margin:0 ; position:relative }
.scroll-group {position:absolute;}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="scroll">content-1<br />content-2<br />content-3<br />content-4<br />content-5<br />content-6<br />content-7<br />content-8<br />content-9<br />content-10<br /></p>
&#13;