Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

anchor tag jump to id top issue

// The function actually applying the offset
function offsetAnchor() {
    if(location.hash.length !== 0) {
        window.scrollTo(window.scrollX, window.scrollY - 100);
    }
}

// This will capture hash changes while on the page
window.addEventListener("hashchange", offsetAnchor);

// This is here so that when you enter the page with a hash,
// it can provide the offset in that case too. Having a timeout
// seems necessary to allow the browser to jump to the anchor first.
window.setTimeout(offsetAnchor, 1); // The delay of 1 is arbitrary and may not always work right (although it did in my testing).
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript döngü dizisi 
Javascript :: alternative for react-tilt 
Javascript :: flip image on x axis phaser 
Javascript :: change y scale phaser 
Javascript :: Alternate capitalization 
Javascript :: phaser place items on circle reverse 
Javascript :: phaser rotate around 
Javascript :: phaser create animation from texture atlas 
Javascript :: phaser play animation after delay 
Javascript :: append input using js 
Javascript :: using cron with bull node js 
Javascript :: npm deploy next js with tailwind 
Javascript :: angular reactive forms bootstrap 4 
Javascript :: docker for node , exoress and coackraz 
Javascript :: Access models in ExpressJS 
Javascript :: Assign A New Method To Every Node 
Javascript :: split array by character javascript 
Javascript :: delete parent js 
Javascript :: js brightness 
Javascript :: localstorage in next js 
Javascript :: regular function javascript 
Javascript :: Javascript count instances of character in a string 
Javascript :: click function in js 
Javascript :: javascript operators 
Javascript :: chart.js 
Javascript :: how to check empty string array in javascript 
Javascript :: js octal 
Javascript :: create file node 
Javascript :: how to get a random item from an array javascript 
Javascript :: how to clear radio field in jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =