Javascript 要在这里添加什么js代码以实现平滑滚动?
请检查下面的JS代码,并建议我进一步添加或修改javascript- JS:Javascript 要在这里添加什么js代码以实现平滑滚动?,javascript,php,jquery,html,css,Javascript,Php,Jquery,Html,Css,请检查下面的JS代码,并建议我进一步添加或修改javascript- JS: JSFIDLE不工作,请检查html和css链接-您可以在showTab()中尝试此功能 你好,普尼特,谢谢你的回复。但是它不工作,你能通过阅读更多的链接来测试它吗,我已经在一个html文件中添加了整个js代码。对不起,伙计,但它不工作 var $tabs = $('.tabs > div'), _currhash, $currTab; $tabs.first().addClass("active"); fun
JSFIDLE不工作,请检查html和css链接-您可以在
showTab()中尝试此功能
你好,普尼特,谢谢你的回复。但是它不工作,你能通过阅读更多的链接来测试它吗,我已经在一个html文件中添加了整个js代码。对不起,伙计,但它不工作
var $tabs = $('.tabs > div'), _currhash, $currTab;
$tabs.first().addClass("active");
function showTab() {
if($currTab.length>0) {
$tabs.removeClass('active');
$currTab.addClass('active');
}
/* find the panels and 'unlink' the id to prevent page jump */
$tabs.each(function() {
var _id = $(this).attr('id');
$(this).attr('id',_id+'_tab');
/* eg we have given the tab an id of 'tab1_tab' */
}); /* set up an anchor 'watch' for the panels */
function anchorWatch() {
if(document.location.hash.length>0) {
/* only run if 'hash' has changed */
if(_currhash!==document.location.hash) {
_currhash = document.location.hash; /* we only want to match the unlinked id's */
$currTab = $(_currhash+'_tab');
showTab();
}
}
}
setInterval(anchorWatch,300);
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);