如何让这个jQuery脚本在WordPress上运行?

This is a slideshow directly added to a page in WordPress. I've added the stylesheet, the script, the slideshow itself and the script which executes the slider function but I just cannot get it in motion.

This is the code of the page:

        //PHP functions
        wp_enqueue_style('slideshow', get_stylesheet_directory_uri() . '/css/slideshow.css', false, '1.1', 'all');
        wp_enqueue_script('jquery.cslider', get_stylesheet_directory_uri() . '/js/jquery.cslider.js', array ('jquery'), 1.1, true);

        <div id="da-slider" class="da-slider">
            <div class="da-slide">
                <h2>1. Easy management</h2>
                <p>Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.</p>
                <a href="#" class="da-link">Read more</a>

                <div class="da-info"></div>
                <div class="da-img da-bg1"></div>
            </div>

            <div class="da-slide">
                <h2>2. Revolution</h2>
                <p>A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p>
                <a href="#" class="da-link">Read more</a>

                <div class="da-info"></div>
                <div class="da-img da-bg2"></div>
            </div>

            <div class="da-slide">
                <h2>3. Warm welcome</h2>
                <p>When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane.</p>
                <a href="#" class="da-link">Read more</a>

                <div class="da-info"></div>
                <div class="da-img da-bg3"></div>
            </div>

            <div class="da-slide">
                <h2>4. Quality Control</h2>
                <p>Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar.</p>
                <a href="#" class="da-link">Read more</a>

                <div class="da-info"></div>
                <div class="da-img da-bg4"></div>
            </div>

            <nav class="da-arrows">
                <span class="da-arrows-prev"></span>
                <span class="da-arrows-next"></span>
            </nav>
        </div>

        <script type="text/javascript">
            jQuery(function() {
                jQuery('#da-slider').cslider({
                    autoplay    : true,
                    bgincrement : 450
                });
            });
        </script>

And here is the cslider's link

douweng5420
douweng5420 您好@pgk可以在回答中转换您的评论吗?所以你可以得到适当的信用
4 年多之前 回复
dongyijing2353
dongyijing2353 PaulThomasGC我刚刚复制并粘贴了这些功能,实际上我不使用版本,我会深入挖掘使用方法
4 年多之前 回复
dsapkqaduj6718493
dsapkqaduj6718493 您是否在代码中的某处加载了Modernizr?因为这个滑块在内部使用Modernizr,我得到一个错误Modernizr没有定义。也许你会把它像wpenqueue函数中的依赖一样?
4 年多之前 回复
dongmi4734
dongmi4734 检查你的jquery版本
4 年多之前 回复
douxi9245
douxi9245 欣赏它可能很难给出一个完整的演示,因为它是一个wordpress构建。几件事情对我来说很突出:get_stylesheet_directory_uri()是否为您提供了正确的目录(即您是否在ChromeDev工具中看到了正确的文件而没有收到任何404错误)。文件版本名称是正确/需要的吗?你似乎在寻找css和js的文件版本1.1-这是正确的吗?其中一个作为字符串('1.1')传递,另一个作为数字(1.1)传递,但我不确定是否重要。
4 年多之前 回复
dsjfrkvn818747
dsjfrkvn818747 请提供任何演示链接。
4 年多之前 回复

2个回答



您必须在 cslider </ code>之前加载 Modernizer </ code>库,因为滑块使用 Modernizer </ code>内部。 当包含 cslider </ code>和 wp_enqueue_script()</ code>函数时,最好的方法是将 Modernizer </ code>作为依赖项传递。</ p>
</ div>

展开原文

原文

You must load Modernizer library before cslider because slider uses Modernizer internally. Maybe the best way is to pass Modernizer as dependency when include cslider with wp_enqueue_script() function.



@pgk你是对的,问题是Modernizr脚本错过了,现在它正在工作!! 非常感谢!! 我必须更加关注Chrome开发工具...... </ p>
</ div>

展开原文

原文

@pgk You are right, the problem was the Modernizr script missed, now it's working!! Thank you so much!! I have to pay more attention to Chrome Dev Tools...

drzrdc1766788
drzrdc1766788 谢谢您的提议,我将发表评论作为答案。
4 年多之前 回复
douxie9347
douxie9347 问他是否可以转换它,他只需要回答而不是评论,你通过点击检查图标接受任何通道。
4 年多之前 回复
douyunjiaok300404
douyunjiaok300404 嗨克莱门斯,抱歉我的无知,但我怎么能这样做?
4 年多之前 回复
duanke6057
duanke6057 您好jos3m,也许您可​​以带@pgk将他的评论转换为答案,这样他就会收到适当的信用,如果不是,请将此答案视为已接受正确关闭。
4 年多之前 回复
立即提问