Javascript 在顶部滚动并使用锚打开新页面
因此,我在我的网站上有一段带有锚jquery页面的代码,这段代码在顶部滚动,但当我单击文本按钮时不会打开新页面 代码js:Javascript 在顶部滚动并使用锚打开新页面,javascript,php,jquery,html,Javascript,Php,Jquery,Html,因此,我在我的网站上有一段带有锚jquery页面的代码,这段代码在顶部滚动,但当我单击文本按钮时不会打开新页面 代码js: $(document).ready(function(){ //Check to see if the window is top if not then display button $(window).scroll(function(){ if ($(this).scrollTop() > 100) { $
$(document).ready(function(){
//Check to see if the window is top if not then display button
$(window).scroll(function(){
if ($(this).scrollTop() > 100) {
$('.scrollToTop').fadeIn();
} else {
$('.scrollToTop').fadeOut();
}
});
//Click event to scroll to top
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
return false;
});
代码html,文本按钮:
<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop">Domestic Electrical installation</a>
<a href="<?php $url->_getURL2('openpage'); ?>" class="scrollToTop">Comercial Electrical installation</a>
感谢您的帮助要在新窗口中打开链接,必须将“目标”属性设置为“空白” 在单击侦听器中,您希望返回true,这样就不会阻止默认行为 $'.scrollToTop'.clickfunction{ $'html,body'。动画{scrollTop:0},800; 返回true; };
删除返回错误
$('.scrollToTop').click(function(){
$('html, body').animate({scrollTop : 0},800);
//return false; This prevents the normal action of the anchor
});
也许可以将target=\u blank添加到您的链接中,以便在新选项卡中打开它们
<a href="<?php $url->_getURL1('openpage'); ?>" class="scrollToTop" target="_blank">Domestic Electrical installation</a>
你的问题到底是什么?你的问题是什么?@ray9209和bipen,我编辑了这个问题。tnxSo当您单击链接时,您希望页面滚动到顶部并在新窗口中打开链接吗?但它目前只是滚动到顶部,而没有在新窗口中打开链接?因此,当单击任何一个链接时,您希望页面向上滚动吗?