简体   繁体   English

如何在 Shopify 网站中使用 jQuery?

[英]How to use jQuery in Shopify website?

I am using shopify for designing my e-Commerce store in which I want my page to be scrolled automatically to the site-menu means header section should be scrolled up.我正在使用 shopify 设计我的电子商务商店,我希望我的页面自动滚动到站点菜单意味着标题部分应该向上滚动。 I used scrollIntoView, but it's not working.我使用了 scrollIntoView,但它不起作用。

In shop.js.liquid I did this much only:在 shop.js.liquid 我只做了这么多:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
timber.srcollIntoView = function() {
  $(wondow).on('load',function(){
    $scrollIntoView.scrollIntoView();
    });
};

I downloaded the jquery.scrollIntoview.min.js from https://github.com/Arwid/jQuery.scrollIntoView/blob/master/jquery.scrollIntoView.min.js and added this one in assets section.我从https://github.com/Arwid/jQuery.scrollIntoView/blob/master/jquery.scrollIntoView.min.js下载了 jquery.scrollIntoview.min.js 并在资产部分添加了这个。 Could you please help me finding the next step?你能帮我找到下一步吗?

If you do this stuff and it's still broken, press F12 in chrome and click on console and post what the error is here and/or leave me a comment.如果您执行此操作但仍然损坏,请在 chrome 中按 F12 并单击控制台并在此处发布错误和/或给我留言。

Add your jquery to the apps.js.liquid file in your assets folder .将您的 jquery 添加到assets文件夹中apps.js.liquid文件。

Example...例子...

(function($){
    $(function(){  //document.ready

        //DOM READY code here

    });

    //Functions, Plugins, Etc.. Here
    //(does not wait for DOM READY STATE) 

})(jQuery);

if you need jquery on the server (might be a good fallback)...如果您需要在服务器上使用 jquery(可能是一个很好的后备)...

use this in your header to include any js file (and maybe jquery) after you upload it to assets folder在您将其上传到资产文件夹后,在您的标头中使用它来包含任何 js 文件(可能还有 jquery)

    <!--[if lte IE 8]>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="{{ jQuery.1.10.1.min.js | asset_url }}"><\/script>');</script>
    <![endif]-->
    <!--[if gt IE 8]><!-->
        <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="{{ jQuery.2.1.3.min.js | asset_url }}');</script>
    <!--<![endif]-->

    <script type="text/javascript" src="{{ 'scrollIntoView.js' | asset_url }}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM