我有一个小问题,文本是可见的,它在 mouseenter 上完美滚动,在 mouseleave 上隐藏,但是当我再次将鼠标悬停时,该功能不起作用。这是代码:
$(document).ready(function (){
var $container = $("#scrollContainer1"),
$ps = $container.find("p"),
containerHeight = $container.height(),
contentHeight = 0,
scrollTop = 0;
($container).hover(function(){
$ps.each(function() {
contentHeight += $(this).outerHeight();
})
$("<div></div>").css("height", 150).appendTo($container).clone().prependTo($container);
setInterval(function() {
if (scrollTop > contentHeight + containerHeight)
scrollTop = 0;
$container.scrollTop(scrollTop++);
}, 20);
});
($container).on("mouseleave", function(){
scrollTop=0;
contentHeight=0;
});
});