Luc
Luc

Reputation: 1825

scrollTo is not a function

Ok, I can't see it anymore. I'm using the scrollTo plugin and have a scrollTo function in my website. It worked and now suddenly it doesn't...

This is my code:

$(document).ready(function() {
    $('header').delay(300).fadeIn(750);
    $('#intro_text').delay(800).fadeIn(750);
    $("#jquery_jplayer_1").jPlayer({
        ready: function () {
            $(this).jPlayer("setMedia", {
                m4v: "mi4.m4v",
                ogv: "mi4.ogv",
                webmv: "mi4.webm",
                poster: "mi4.png"
            });
        },
        swfPath: "js",
        supplied: "webmv, ogv, m4v",
        size: {
            width: "570px",
            height: "340px",
            cssClass: "jp-video-360p"
        }
    });
});

$(function(toDemos) {
 $('h1').click(function() {
        $.scrollTo('#intro', 800);
    });
});

$(function(toDemos) {
 $('#contact').click(function() {
        $.scrollTo('footer', 800);
    });
});

$(function(toDemos) {
 $('#demos').click(function() {
        $.scrollTo('#content', 800);
    });
});

$(function(toDemos) {
 $('#toTop').click(function() {
        $.scrollTo('#intro', 800);
    });
});

$(function() {
    $("#playlist li").on("click", function() {
        $("#videoarea").attr({
            "src": $(this).attr("movieurl"),
            "poster": "",
            "autoplay": "autoplay"
        })
    })
    $("#videoarea").attr({
        "src": $("#playlist li").eq(0).attr("movieurl"),
        "poster": $("#playlist li").eq(0).attr("moviesposter")
    })
})

I'm just a beginner at this, but I don't think I did much wrong. Is there anything wrong here? I can't see it.

Hopefully one of you can! Much thanks in advance.

Upvotes: 7

Views: 37898

Answers (2)

Daut
Daut

Reputation: 2625

This is quite old question but I thought I would share my way :)

$("button").on('click', function() {
	window.scrollTo({
    top: $('#intro').offset().top,
    left: 0,
    behavior: 'smooth'
  })
});
.wrapper {

  height:1000px;
  width: 300px;
  background: #eee;
}

.other {
  height: 500px;
  background: #ddd;
  padding: 20px;
  width: 100%;
}

#intro {
  height: 500px;
  background: #bbb;
  padding: 20px;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>Click</button>
<div class="wrapper">
  <div class="other">Other div</div>
  <div id="intro">
    Intro
  </div>
</div>

Upvotes: 1

Brian Phillips
Brian Phillips

Reputation: 4425

If you're using flesler's scrollTo plugin, you may need to modify the duration option:

$.scrollTo('footer', { duration:800 });

Download the plugin source here if you haven't already. I would verify that it is correctly linked to your code. Also try a debugging tool like firebug to help with the troubleshooting.

NOTE:

To point out Mark's answer in the comments below for anyone who stumbles on this, jQuery must be linked first in order in the file before any plugins are loaded. E.g.:

<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery.scrollTo.min.js"></script>

Upvotes: 6

Related Questions