我有这个JS可以工作,但它在页面完成加载之前开始滚动。有没有办法检查页面加载,然后加载以获得平滑效果?
>>> A = 10*np.ones((5,5,3), dtype=int)
>>> A -= [2, 5, 3]
>>> A[:,:,0] # Red
array([[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8],
[8, 8, 8, 8, 8]])
>>> A[:,:,1] # Green
array([[5, 5, 5, 5, 5],
[5, 5, 5, 5, 5],
[5, 5, 5, 5, 5],
[5, 5, 5, 5, 5],
[5, 5, 5, 5, 5]])
>>> A[:,:,2] # Blue
array([[7, 7, 7, 7, 7],
[7, 7, 7, 7, 7],
[7, 7, 7, 7, 7],
[7, 7, 7, 7, 7],
[7, 7, 7, 7, 7]])
此外,jQuery(document).ready(function(){
var href = window.location.href+'#team';
var splitit = (href.split('#'))[1];
if(splitit !== "" || splitit !== "undefined"){
jQuery('html, body').animate({
scrollTop: jQuery('#'+splitit).offset().top - 50
}, 2000);
}
});
做了什么?我们可以将其删除吗?
答案 0 :(得分:1)
split()方法用于将字符串拆分为子字符串数组,并返回新数组。
var str = "How are you doing today?";
var res = str.split(" ");
//result is array [How,are,you,doing,today?]
删除什么? 检查所需的分裂是在网址'#' - '#'后的符号或非空网址。
尝试在页面完全加载时运行的加载事件,包括图形。
jQuery( window ).load(function() {
// Run code
});
答案 1 :(得分:0)
splitit是目标的id属性,应该滚动页面。
实际上,如何检查是否已加载所有资源并不是很明显,但是您可以将此jquery代码放在页面的末尾,我认为它可以帮助您。
答案 2 :(得分:0)
对于此功能,您可以使用现代浏览器的 css:
html {
scroll-behavior: smooth;
}
但我推荐这种方法:在 document.ready 中调用 smoothScroll()
function smoothScroll(){
// this part will add ID's to the named anchor tags
// please name tags names not to interfere with other elements id's but
// also will look good in addressbar, as : #ListOfFeaturedProductsSection
$("a").each(function(){
var t=this;
if (t.name!=="" && t.id==""){
t.id=t.name;
}
});
// Add smooth scrolling to all links
$("a").on('click', function(event) {
// Make sure this.hash has a value before overriding default behavior
if (this.hash !== "") {
// Prevent default anchor click behavior
var hash = this.hash;
if (hash) {
event.preventDefault();
// Using jQuery's animate() method to add smooth page scroll
// The optional number (800) specifies the number of milliseconds it takes to scroll to the specified area
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 800, function(){
// Add hash (#) to URL when done scrolling (default click behavior)
window.location.hash = hash;
});
}
}
});
}