Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript-如何快速滚动页面直到用户释放鼠标按钮_Javascript_Jquery_Vertical Scrolling - Fatal编程技术网

javascript-如何快速滚动页面直到用户释放鼠标按钮

javascript-如何快速滚动页面直到用户释放鼠标按钮,javascript,jquery,vertical-scrolling,Javascript,Jquery,Vertical Scrolling,Shor问题-在触摸屏显示不太好的pc上打开的页面。我创建了两个大箭头,但不知道如何使用JS/jQuery编程 第一次尝试:onClick->scroll-它可以工作,但用户必须多次点击才能滚动文章。 第二: 不起作用;) 我正在尝试模拟真实的浏览器滚动箭头-直到你保持鼠标按键页面向下(或向上)滚动。你上面的代码无法工作,因为JavaScript不是多线程的。也就是说,while循环正在消耗CPU,可能会阻止其他代码运行(即mouseup事件) 不久前我做过类似的事情。请随时查看我的博客文章 另

Shor问题-在触摸屏显示不太好的pc上打开的页面。我创建了两个大箭头,但不知道如何使用JS/jQuery编程

第一次尝试:onClick->scroll-它可以工作,但用户必须多次点击才能滚动文章。 第二:

不起作用;)
我正在尝试模拟真实的浏览器滚动箭头-直到你保持鼠标按键页面向下(或向上)滚动。

你上面的代码无法工作,因为JavaScript不是多线程的。也就是说,while循环正在消耗CPU,可能会阻止其他代码运行(即mouseup事件)

不久前我做过类似的事情。请随时查看我的博客文章

另外,不确定您是否正在这样做,但请确保将所有JavaScript代码都放在jQuery的ready()函数中;否则,jQuery可能找不到#scUp元素

以下是我以前的博文中的相关代码:

var scrollTimer;
function scrollContent(amt)
{
    $("#content").scrollTop($("#content").scrollTop()+amt);
    scrollTimer = window.setTimeout("scrollContent(" + amt + ")", 25);
}
$(document).ready(function ()
{
    $("#content").css("overflow", "hidden");
    $("#scrollUp").mousedown(function() {
        window.clearTimeout(scrollTimer); //Not necessary, but just to be sure...
        $("#scrollUp").animate({"opacity": 100}, 'fast');
        scrollContent(-10);
    });
    $("#scrollUp").mouseup(function() {
        window.clearTimeout(scrollTimer);
        $("#scrollUp").animate({"opacity": 0}, 'fast');
    });
    $("#scrollDown").mousedown(function() {
        window.clearTimeout(scrollTimer); //Not necessary, but just to be sure...
        $("#scrollDown").animate({"opacity": 100}, 'fast');
        scrollContent(10);
    });
    $("#scrollDown").mouseup(function() {
        window.clearTimeout(scrollTimer);
        $("#scrollDown").animate({"opacity": 0}, 'fast');
    });
    //$("#scrollUp").css("opacity", 0); //Alternative
    $("#scrollUp").animate({"opacity": 0}, 'slow');
    $("#scrollDown").animate({"opacity": 0}, 'slow');
});
…以及链接:


希望这有帮助

与此同时,我编写了以下代码:

     var scrollId = 0;

 $("#scUp").mouseup(function(){
  $(this).css("opacity", 0.3);
  clearInterval(scrollId);

 }).mousedown(function(){
  $(this).css("opacity", 1);
  var scroll = function() { $("html, body").stop().animate({ scrollTop: "-=10px" }, 15); }
  scroll();
  scrollId = setInterval(scroll, 15);          
 });

 $("#scDw").mouseup(function(){
  $(this).css("opacity", 0.3);
  clearInterval(scrollId);

 }).mousedown(function(){
  $(this).css("opacity", 1);
  var scroll = function() { $("html, body").stop().animate({ scrollTop: "+=10px" }, 15); }
  scroll();
  scrollId = setInterval(scroll, 15);          
 });
它对歌剧有效,但对歌剧无效。。。有趣的是,kiosk是基于Opera浏览器的,有什么解决方案吗

顺便问一下,有没有关于在Linux上使用FF构建kiosk(1.x版FF没有过时)的资料(Linux对我来说没有问题,但我正在搜索FF的安全插件)。

我很久以前回答过。。。基本上,它在鼠标按下时设置一个标志,在鼠标上升时清除。然后一个
setTimeout
循环直到标志清除。此外,它还具有鼠标滚轮和拖放功能

退房


var值=2;
函数scrollAs(值){
如果(值)滚动值=值;
document.body.scrollTop+=(scrollValue-2)*10;
如果(scrollValue!=2)设置超时(scrollAs,100);
}
以下是您的Opera错误修复:
     var scrollId = 0;

 $("#scUp").mouseup(function(){
  $(this).css("opacity", 0.3);
  clearInterval(scrollId);

 }).mousedown(function(){
  $(this).css("opacity", 1);
  var scroll = function() { $("html, body").stop().animate({ scrollTop: "-=10px" }, 15); }
  scroll();
  scrollId = setInterval(scroll, 15);          
 });

 $("#scDw").mouseup(function(){
  $(this).css("opacity", 0.3);
  clearInterval(scrollId);

 }).mousedown(function(){
  $(this).css("opacity", 1);
  var scroll = function() { $("html, body").stop().animate({ scrollTop: "+=10px" }, 15); }
  scroll();
  scrollId = setInterval(scroll, 15);          
 });
<div style="position:fixed">
<a href="javascript://" onmousedown="scrollAs(1);" onmouseup="scrollAs(2);">Up</a>
<a href="javascript://" onmousedown="scrollAs(3);" onmouseup="scrollAs(2);">Down</a>
</div>

<script>
var scrollValue = 2;
function scrollAs(value) {
  if(value) scrollValue = value;
  document.body.scrollTop += (scrollValue - 2)*10;
  if(scrollValue != 2) setTimeout(scrollAs, 100);
}
<script>