[{"data":1,"prerenderedAt":223},["ShallowReactive",2],{"\u002Farticles\u002Fsmooth-anchors":3},{"id":4,"title":5,"body":6,"createdAt":213,"description":214,"extension":215,"meta":216,"navigation":217,"path":218,"rawbody":219,"seo":220,"stem":221,"__hash__":222},"articles\u002Farticles\u002Fsmooth-anchors.md","Smooth Anchors",{"type":7,"value":8,"toc":211},"minimark",[9,21,24,73,76,190,196,199,207],[10,11,12,13,20],"p",{},"Long web pages usually have an anchor that takes you back to the top of the page. In most cases, the browser will skip right to the top when a user clicks that link. But using ",[14,15,19],"a",{"href":16,"rel":17},"http:\u002F\u002Fjquery.com\u002F",[18],"nofollow","jQuery",", you can easily make your “Top of Page” anchors more pleasant.",[10,22,23],{},"First, you need your anchored link:",[25,26,31],"pre",{"className":27,"code":28,"language":29,"meta":30,"style":30},"language-html shiki shiki-themes github-light github-dark","Going Up? \u003Ca href=\"#top\" id=\"back-to-top\">Top\u003C\u002Fa>\n","html","",[32,33,34],"code",{"__ignoreMap":30},[35,36,39,43,46,50,53,57,60,62,65,68,70],"span",{"class":37,"line":38},"line",1,[35,40,42],{"class":41},"sVt8B","Going Up? \u003C",[35,44,14],{"class":45},"s9eBZ",[35,47,49],{"class":48},"sScJk"," href",[35,51,52],{"class":41},"=",[35,54,56],{"class":55},"sZZnC","\"#top\"",[35,58,59],{"class":48}," id",[35,61,52],{"class":41},[35,63,64],{"class":55},"\"back-to-top\"",[35,66,67],{"class":41},">Top\u003C\u002F",[35,69,14],{"class":45},[35,71,72],{"class":41},">\n",[10,74,75],{},"Now, add in a simple jQuery function to make the jump a bit smoother:",[25,77,81],{"className":78,"code":79,"language":80,"meta":30,"style":30},"language-js shiki shiki-themes github-light github-dark","$(document).ready(function(){\n    $('#back-to-top').click(function(e){\n        e.preventDefault();\n        $('html,body').animate({scrollTop:0},'slow');\n    });\n});\n","js",[32,82,83,104,134,146,178,184],{"__ignoreMap":30},[35,84,85,88,91,94,97,101],{"class":37,"line":38},[35,86,87],{"class":48},"$",[35,89,90],{"class":41},"(document).",[35,92,93],{"class":48},"ready",[35,95,96],{"class":41},"(",[35,98,100],{"class":99},"szBVR","function",[35,102,103],{"class":41},"(){\n",[35,105,107,110,112,115,118,121,123,125,127,131],{"class":37,"line":106},2,[35,108,109],{"class":48},"    $",[35,111,96],{"class":41},[35,113,114],{"class":55},"'#back-to-top'",[35,116,117],{"class":41},").",[35,119,120],{"class":48},"click",[35,122,96],{"class":41},[35,124,100],{"class":99},[35,126,96],{"class":41},[35,128,130],{"class":129},"s4XuR","e",[35,132,133],{"class":41},"){\n",[35,135,137,140,143],{"class":37,"line":136},3,[35,138,139],{"class":41},"        e.",[35,141,142],{"class":48},"preventDefault",[35,144,145],{"class":41},"();\n",[35,147,149,152,154,157,159,162,165,169,172,175],{"class":37,"line":148},4,[35,150,151],{"class":48},"        $",[35,153,96],{"class":41},[35,155,156],{"class":55},"'html,body'",[35,158,117],{"class":41},[35,160,161],{"class":48},"animate",[35,163,164],{"class":41},"({scrollTop:",[35,166,168],{"class":167},"sj4cs","0",[35,170,171],{"class":41},"},",[35,173,174],{"class":55},"'slow'",[35,176,177],{"class":41},");\n",[35,179,181],{"class":37,"line":180},5,[35,182,183],{"class":41},"    });\n",[35,185,187],{"class":37,"line":186},6,[35,188,189],{"class":41},"});\n",[10,191,192],{},[193,194,195],"em",{},"Note: Be sure to include a copy of jQuery before calling this function.",[10,197,198],{},"Breaking down this simple code, we assign a function to the click event for #back-to-top.",[10,200,201,202,206],{},"In that function we prevent the default action, and use jQuery’s ",[14,203,161],{"href":204,"rel":205},"http:\u002F\u002Fapi.jquery.com\u002Fanimate\u002F",[18]," to scroll to the top of html and body.",[208,209,210],"style",{},"html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":30,"searchDepth":106,"depth":106,"links":212},[],"2011\u002F02\u002F23","Long web pages usually have an anchor that takes you back to the top of the page. In most cases, the browser will skip right to the top when a user clicks that link. But using jQuery, you can easily make your “Top of Page” anchors more pleasant.","md",{},true,"\u002Farticles\u002Fsmooth-anchors","---\ntitle: Smooth Anchors\ncreatedAt: 2011\u002F02\u002F23\n---\nLong web pages usually have an anchor that takes you back to the top of the page. In most cases, the browser will skip right to the top when a user clicks that link. But using [jQuery](http:\u002F\u002Fjquery.com\u002F), you can easily make your “Top of Page” anchors more pleasant.\n\nFirst, you need your anchored link:\n\n```html\nGoing Up? \u003Ca href=\"#top\" id=\"back-to-top\">Top\u003C\u002Fa>\n```\n\nNow, add in a simple jQuery function to make the jump a bit smoother:\n\n```js\n$(document).ready(function(){\n\t$('#back-to-top').click(function(e){\n\t\te.preventDefault();\n\t\t$('html,body').animate({scrollTop:0},'slow');\n\t});\n});\n```\n\n_Note: Be sure to include a copy of jQuery before calling this function._\n\nBreaking down this simple code, we assign a function to the click event for #back-to-top.\n\nIn that function we prevent the default action, and use jQuery’s [animate](http:\u002F\u002Fapi.jquery.com\u002Fanimate\u002F) to scroll to the top of html and body.\n",{"title":5,"description":214},"articles\u002Fsmooth-anchors","J9LYEUT4LmXkz8CxOgQmIMyEcz25wk86mXmGuHJCcSg",1794877726944]