mirror of
				https://gitee.com/vant-contrib/vant.git
				synced 2025-11-04 04:42:09 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			18 lines
		
	
	
		
			325 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			18 lines
		
	
	
		
			325 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
export function scrollToAnchor(selector) {
 | 
						|
  let count = 0;
 | 
						|
 | 
						|
  const timer = setInterval(() => {
 | 
						|
    const el = document.querySelector(selector);
 | 
						|
    if (el) {
 | 
						|
      el.scrollIntoView();
 | 
						|
      clearInterval(timer);
 | 
						|
    } else {
 | 
						|
      count++;
 | 
						|
 | 
						|
      if (count > 10) {
 | 
						|
        clearInterval(timer);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }, 100);
 | 
						|
}
 |