最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery slick (carousel) plugin not working - Stack Overflow

programmeradmin4浏览0评论

I'm trying to use this jQuery plugin ( / ) to a carousel. I tried many different plugins, but I always face some kind of error. So, I'm sticking with this until I figure out whats wrong.

Here is my HTML head:

<head>
    <!--[if lt IE 9]>
        <script src='.js'></script>
    <![endif]-->
    <meta charset='utf-8' />
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <script type="text/javascript" src=".min.js"></script>
    <link rel="stylesheet" type="text/css" href="slick/slick.
        <script type=" text/javascript " src="slick/slick.min.js "></script>
        <script type="text/javascript " src='/js/carousel.js'></script>
</head>

When I tried it, I got an 'Uncaught TypeError: undefined is not a function' at line to of my JS where I call the function 'slick'. Here it where I call it:

<div class="slider single-items"><div></div><div></div><div></div></div>

And here is my carousel.js:

$(document).ready(function () {
    $('.single-item').slick({
        dots: true,
        infinite: true,
        speed: 300,
        slidesToShow: 1,
        slidesToScroll: 1,
        autoplay: true
    });
});

I'm trying to use this jQuery plugin ( http://kenwheeler.github.io/slick/ ) to a carousel. I tried many different plugins, but I always face some kind of error. So, I'm sticking with this until I figure out whats wrong.

Here is my HTML head:

<head>
    <!--[if lt IE 9]>
        <script src='http://html5shiv.googlecode./svn/trunk/html5.js'></script>
    <![endif]-->
    <meta charset='utf-8' />
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <script type="text/javascript" src="http://code.jquery./jquery-latest.min.js"></script>
    <link rel="stylesheet" type="text/css" href="slick/slick.
        <script type=" text/javascript " src="slick/slick.min.js "></script>
        <script type="text/javascript " src='/js/carousel.js'></script>
</head>

When I tried it, I got an 'Uncaught TypeError: undefined is not a function' at line to of my JS where I call the function 'slick'. Here it where I call it:

<div class="slider single-items"><div></div><div></div><div></div></div>

And here is my carousel.js:

$(document).ready(function () {
    $('.single-item').slick({
        dots: true,
        infinite: true,
        speed: 300,
        slidesToShow: 1,
        slidesToScroll: 1,
        autoplay: true
    });
});
Share Improve this question edited Jan 14, 2016 at 16:36 Carlos asked Jun 26, 2014 at 13:07 CarlosCarlos 3862 gold badges13 silver badges33 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

I had similar problem, but in my case issue was following:

I had installed slick by bower install slick instead bower install slick.js which caused that I had totally different library included in my dependecies.

You are selecting $('.single-item'), but your markup has elements with class single-items (with a "s" at the end). Assuming this pasted code is correct, your jQuery should be changed to $('.single-items').

$(document).ready(function () {
    $('.single-items').slick({
        dots: true,
        infinite: true,
        speed: 300,
        slidesToShow: 1,
        slidesToScroll: 1,
        autoplay: true
    });
});

JSFiddle: http://jsfiddle/N6wfG/

发布评论

评论列表(0)

  1. 暂无评论