【问题标题】:Auto refresh and auto scroll up and down in one script在一个脚本中自动刷新和自动上下滚动
【发布时间】:2016-09-16 08:18:44
【问题描述】:

我已经有单独的自动刷新代码和自动滚动代码。

我希望它们在一个功能中...我该怎么做?

这是我的自动刷新

代码
var auto_refresh = setInterval(function ()
{
  $('#load_tweets').load('http://myayg.com/index.php?route=salesTracker2.results').fadeIn("slow");
}, 10000); 

还有我的自动滚动

function scroll(speed) {
  $('html, body').animate({ scrollTop: $(document).height() }, speed, function() {
    $(this).animate({ scrollTop: 0 }, speed);
  });
}

speed = 30000;

scroll(speed)
setInterval(function(){scroll(speed)}, speed * 2);

我希望它们在一个脚本中...我该怎么做?

【问题讨论】:

    标签: javascript php autoscroll


    【解决方案1】:

    这应该可以工作....

    function doRefreshAndScroll(speed) {
      $('#load_tweets').load('http://myayg.com/index.php?route=salesTracker2.results', function(){
        $('html, body').animate({ scrollTop: $(document).height() }, speed, function() {
          $(this).animate({ scrollTop: 0 }, speed);
        });
      }).fadeIn("slow")
    }
    
    var speed = 30000
    setInterval(doRefreshAndScroll(speed), speed * 2)
    

    【讨论】:

    • 嗨@Pranesh,您的代码有一个错误提示 index.php?route=salesTracker2.results:224 Uncaught ReferenceError: setIdoRefreshAndScroll is not defined
    • 嗨,@Pranesh,它可以工作,但文字在颤抖......我认为代码很混乱
    • 你测试过这个@Pranesh 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 1970-01-01
    • 2012-05-06
    • 2014-03-23
    相关资源
    最近更新 更多