2016-09-16 27 views
0

我已經有單獨的自動刷新代碼和自動滾動代碼。自動刷新和自動向上和向下滾動一個腳本

我希望他們在一個功能...我該怎麼做?

這裏是我的自動代碼刷新

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); 

我希望他們在一個腳本...我怎麼能這樣做?

回答

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) 
+0

嗨@Pranesh,你的代碼中有一個錯誤說 的index.php路線= salesTracker2.results:224未捕獲的ReferenceError:未定義setIdoRefreshAndScroll –

+0

同樣的錯誤@Pranesh –

+0

嗨,@Pranesh,它的工作原理,但詞語在顫抖......我認爲這些代碼很混亂 –