{"id":292,"date":"2020-12-29T19:24:49","date_gmt":"2020-12-29T19:24:49","guid":{"rendered":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/http\/code.oxyset.com\/?p=292"},"modified":"2026-10-10T20:52:39","modified_gmt":"2026-10-10T20:52:39","slug":"rotate-logo-on-scroll","status":"publish","type":"post","link":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/rotate-logo-on-scroll\/","title":{"rendered":"Rotate the Logo on Scroll in WordPress"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A round logo that turns as you scroll is a small detail that makes a WordPress site feel alive. Matthias Altmann used it on his site and shared the idea. This snippet rotates the logo on scroll: the further down the page, the more it turns, and scrolling back up turns it back.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is plain JavaScript, so it works with block themes, which do not load jQuery on the front end, and it stays off for visitors who asked their system for reduced motion.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The snippet<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"js\" class=\"language-js\">(function () {\n\t\/\/ ===== Config =====\n\tvar SELECTOR = '.wp-block-site-logo img'; \/\/ The logo to rotate.\n\tvar SPEED = 0.5; \/\/ Degrees per pixel scrolled.\n\t\/\/ ===== End of config =====\n\n\tvar logos = document.querySelectorAll(SELECTOR);\n\tif (!logos.length || window.matchMedia('(prefers-reduced-motion: reduce)').matches) {\n\t\treturn;\n\t}\n\n\tvar ticking = false;\n\n\tfunction rotate() {\n\t\tticking = false;\n\t\tvar deg = window.scrollY * SPEED;\n\t\tlogos.forEach(function (logo) {\n\t\t\tlogo.style.transform = 'rotate(' + deg + 'deg)';\n\t\t});\n\t}\n\n\twindow.addEventListener('scroll', function () {\n\t\tif (!ticking) {\n\t\t\tticking = true;\n\t\t\twindow.requestAnimationFrame(rotate);\n\t\t}\n\t}, { passive: true });\n\n\trotate(); \/\/ Right angle when the page loads already scrolled.\n})();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By default it rotates the image in the core <strong>Site Logo<\/strong> block. For a logo from a page builder or a custom header, change <code>SELECTOR<\/code> to its class or ID.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Add it with Scripts Organizer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/dplugins.com\/downloads\/scripts-organizer\/\">Scripts Organizer<\/a> go to <strong>Code Blocks \u2192 Add New<\/strong> and give the block a name. Set <strong>Trigger location<\/strong> to <strong>Conditions<\/strong> and set <strong>Template<\/strong> to <strong>All<\/strong>, or narrow it to the pages that need the script. Under <strong>Script location<\/strong> tick <strong>Footer<\/strong>, set <strong>Footer Mode<\/strong> to <strong>Javascript<\/strong>, paste the code into the footer editor and publish.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Scripts Organizer prints header and footer code on the front end only with the <strong>Conditions<\/strong> trigger, not with <strong>Everywhere<\/strong>, and it adds the <code>&lt;script&gt;<\/code> tag itself, so paste the code without one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How it works<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>On every scroll the angle is <code>window.scrollY * SPEED<\/code>, so 0.5 means one full turn per 720 pixels scrolled.<\/li>\n\n\n<li>Scroll events fire faster than the screen repaints. The <code>ticking<\/code> flag and <code>requestAnimationFrame()<\/code> update the logo at most once per frame.<\/li>\n\n\n<li>The listener is <code>passive<\/code>, which tells the browser it never blocks scrolling.<\/li>\n\n\n<li><code>rotate()<\/code> also runs once on load, so a page opened halfway down (after a reload or an anchor link) shows the right angle at once.<\/li>\n\n\n<li>When the visitor has <strong>reduce motion<\/strong> turned on in their system settings, the script does nothing.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Customise it<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Faster or slower: change <code>SPEED<\/code>. Use a negative value to turn the other way.<\/li>\n\n\n<li>Smoother: add <code>.wp-block-site-logo img { transition: transform 0.2s linear; }<\/code> in a Header code block with <strong>Header Mode<\/strong> <strong>CSS<\/strong>.<\/li>\n\n\n<li>Other effects: see <a href=\"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/animate-header-logo-on-scroll\/\">Animate header logo on scroll<\/a> for shrinking the logo instead.<\/li>\n\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Gotchas<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Rotation turns the whole image, including its corners. Square logos with a background look odd; use a round or transparent logo.<\/li>\n\n\n<li>If the logo is a link with a focus outline, the outline rotates too.<\/li>\n\n<\/ul>\n\n","protected":false},"excerpt":{"rendered":"<p>Rotate your WordPress site logo as the visitor scrolls, with a few lines of plain JavaScript that respect reduced-motion settings.<\/p>\n","protected":false},"author":1,"featured_media":46826,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"Rotate the Logo on Scroll in WordPress - Code DPlugins","description":"Rotate your WordPress site logo as the visitor scrolls, with a few lines of plain JavaScript that respect reduced-motion settings."},"_slim_seo_primary_term_category":0,"_slim_seo_primary_term_post_tag":0,"footnotes":""},"categories":[73],"tags":[],"dpc_library":[204],"class_list":["post-292","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/comments?post=292"}],"version-history":[{"count":1,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":46825,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/posts\/292\/revisions\/46825"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media\/46826"}],"wp:attachment":[{"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/media?parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/categories?post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/tags?post=292"},{"taxonomy":"dpc_library","embeddable":true,"href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/code.dplugins.com\/wp-json\/wp\/v2\/dpc_library?post=292"}],"curies":[{"name":"wp","href":"https:\/\/summer-heart-0930.chufeiyun1688.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}