首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >锚定标记在NetSuite (SuiteCommerce Advanced)中跳到页面的一半

锚定标记在NetSuite (SuiteCommerce Advanced)中跳到页面的一半
EN

Stack Overflow用户
提问于 2021-05-14 20:10:56
回答 1查看 64关注 0票数 1

NetSuite SuiteCommerce不支持锚点标记吗?我想包括一些链接,在我的页面顶部,让观众跳到那个类别(在同一页)。我知道我已经正确地设置了我的代码,但是所发生的一切只是尝试打开一个没有内容的新页面:

https://www.prospectfastener.com/product-interchange

EN

回答 1

Stack Overflow用户

发布于 2022-02-07 16:48:37

与NetSuite SuiteCommerce一起使用Anchor标记

从其他与骨干有关的问题中收集了几个答案。这可以用于自定义扩展,也可以作为内联脚本放置到SMT CMS HTML内容中。

用SC 2022.1测试

代码语言:javascript
复制
// This breaks the function out of the try/catch for use on page
var scrollToAnchorFn = null;
// SB env keeps doubling loading inline scripts for testing
// This tests/sets its own property on the window to test against for that
if (typeof window.anchorSet === 'undefined') {
  try {
    window.anchorSet = true;
    // Call scrollToAnchor with anchor ID whenever you want to jump between points on a page
    const scrollToAnchor = (anchorId) => {
      try {
        var aTag = $(anchorId);
        $('html,body').animate({
            scrollTop: aTag.offset().top
          },
          'slow',
        );
      } catch (err) {
        console.error(err);
      }
    };

    const initAnchorScroll = () => {
      // Test if jQuery is loaded yet, if not set timeout and repeat fn
      if (window.jQuery) {
        // Check if document is already loaded and ready, run code now if dom is ready
        if (document.readyState === 'complete')
          return scrollToAnchor(PageHash);
        // Before images or styling is finished loading, move to part of dom requested which is ready
        return $(document).ready(() => {
          scrollToAnchor(PageHash);
        });
      }
      setTimeout(function() {
        initAnchorScroll();
      }, 50);
    };

    // Get our page hash
    //  const PageHash = window.location.hash;
    // Snippet demo hash
    const PageHash = '#testAnchor';

    // Initialize on page load if hash detected in url
    // Since hashes return the #, 
    // we want a length greater than 1 to ensure there is an id
    if (PageHash.length > 1) initAnchorScroll();
    scrollToAnchorFn = scrollToAnchor;
  } catch (err) {
    console.error(err);
  }
}
代码语言:javascript
复制
.fillerDiv {
  height: 100vh;
  width: 1000vw;
  background-color: #fedd00;
}

#testAnchor {
  background-color: #4285f4;
  color: #ffffff;
}
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div class="container">
  <div class="fillerDiv"></div>
  <div id="testAnchor">this is test content down the page with anchor ID.
    <a href="#" onclick="scrollToAnchorFn('#testAnchor2');">Go to Next Anchor</a></div>
  <div class="fillerDiv "></div>
  <div id="testAnchor2">Second anchor tag</div>
  <div class="fillerDiv "></div>
</div>

旧答案

我会假设不是,但我很高兴错了。

注意:内容传递不支持锚标记。

NetSuite应用套件--理解内容传递

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67540450

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档