我想从滑块设置一个按钮,在折叠下方向下滚动,让外部的“让我说话”按钮变为可见并浮动。向下滚动时,这个“让我们说话”按钮跟随你。如果单击此按钮,则会转到外部站点。
现在,如果您点击这个JavaScript会将您带到顶部,但我希望这会转到外部网站。请提供一些有用的建议来修改此脚本。
jQuery(document).ready(function($){
"use strict";// browser window scroll (in pixels) after which the "back to top" link is shown
var offset = 300,
//browser window scroll (in pixels) after which the "back to top" link opacity is reduced
offset_opacity = 1200,
//duration of the top scrolling animation (in ms)
scroll_top_duration = 700,
//grab the "back to top" link
$back_to_top = $('.cd-top');
//hide or show the "back to top" link
$(window).scroll(function(){
( $(this).scrollTop() > offset ) ? $back_to_top.addClass('cd-is-visible') : $back_to_top.removeClass('cd-is-visible cd-fade-out');
if( $(this).scrollTop() > offset_opacity ) {
$back_to_top.addClass('cd-fade-out');
}
});
//smooth scroll to top
$back_to_top.on('click', function(event){
event.preventDefault();
$('body,html').animate({
scrollTop: 0 ,
}, scroll_top_duration
);
});
});
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
答案 0 :(得分:0)
如果你只是想要回到顶部按钮带你到另一个页面,只需替换
$back_to_top.on('click', function(event){
event.preventDefault();
$('body,html').animate({
scrollTop: 0 ,
}, scroll_top_duration
);
});
到这个
$back_to_top.on('click', function(event){
event.preventDefault();
window.location.replace('http://www.yoursite.com');
});