下载文件并在 link 上滚动到底部 div 单击

Download a file and scroll to bottom div on link click

在 link 单击时,我希望用户下载一个文件(在 href 中)。在同一个点击中,我想同时将它们向下滚动到一个表单。

根据我的代码,我只能做其中之一。我无法执行这两个操作。

HTML

<a href="http://www.cdc.gov/animalimportation/images/dog2.jpg" download="dog2.jpg"
    class="scroll-to-bottom-link">Scroll to bottom</a>
<p>here is some secondary information</p>

jQuery

$('.scroll-to-bottom-link').click(function(){
$('html, body').animate({scrollTop : $('body').height() }, 800);
return false;
});

关于如何做到这一点有什么想法吗?我找到的其他选项使用 href="#",但我需要它来下载。

您必须删除 return false,因为它会调用 preventDefault(),这会阻止下载。

够了:

$('.scroll-to-bottom-link').click(function(){
   $('html, body').animate({scrollTop : $('body').height() }, 800);
});

DEMO

我会在 a 标签中放置一个 div 并将事件附加到它

   <a href="http://www.cdc.gov/animalimportation/images/dog2.jpg" download ><div class="scroll-to-bottom-link">Scroll to bottom</div></a>
    <p>here is some secondary information</p>

然后从函数中删除 remove false

$('.scroll-to-bottom-link').click(function(){
    $('html, body').animate({scrollTop : $('body').height() }, 800);
});

JSFiddle