0

Solved thanks to Matt!

So this is an odd bug ive come across redoing my new site. I have added a testimonial second on one page and it seems to have "broken" the smooth scroll Jquery I had working.

The Beta site is here... www.anim-house.co.uk You can see the scroll working fine. On www.anim-house.co.uk/portfolio.html The scroll does not work - the addition of

$(document).ready(function(){
    $('#fade').list_ticker({
        speed:14000,
        effect:'fade'
    });     
});

Seems to have broken it? Im amateur when it comes to Jquery if someone could look through and figure out the error id greatly appreciate it.

7
  • I should add that even removing the new code and reverting back to my old portfolio page the site still does not scroll. Commented Apr 17, 2013 at 23:22
  • jQuery is loading, open a debug console and type "jQuery" Commented Apr 17, 2013 at 23:23
  • var targetOffset = $target.offset().top; this line Commented Apr 17, 2013 at 23:24
  • $target is undefined. var $target = $(this.hash) sets target. Commented Apr 17, 2013 at 23:25
  • @Blender I do not think that is true. Commented Apr 17, 2013 at 23:40

2 Answers 2

1
$('a[href*=#]').each(function() { console.log(this.hash)})
#contact
#cgi
#web-design
#graphic-design
#motion-graphics
#photography
#home
#cgi
#web-design
#graphic-design
#motion-graphics
#photography
#home
null
null
null

It is those last three that are causing the error. They are related to links with href="#". Instead of checking for

if(target) {

Check for

if ($target  && target) {

EDIT: OP got it working with this: http://paulund.co.uk/smooth-scroll-to-internal-links-with-jquery

The website looks very nice, by the way.

Sign up to request clarification or add additional context in comments.

3 Comments

As soon as get this bug fixed I will be over the moon. And thanks - Amateur web designer here trying to flex my muscles with this site.
Ive replaced if(target) { with if ($target && target) { on like 65, no effect.
Just uploaded the latest code on index + portfolio line 65 has been edited how you have suggested.
1

You have an error in your portfolio.html:

This is what I got from the Chrome dev-tools:

Uncaught TypeError: Cannot read property 'top' of undefined at line 66

The affected line is:

var targetOffset = $target.offset().top;

After getting that error, the browser stops processing and your plugin is likely not loaded. Fixing this error should fix the rest as well (provided there are no other errors)

8 Comments

How is it working on my index page then? And how would I go about fixing this bug.. Like I say im a noob at jQuery.
@Alex the error is caused by links that have href="#", which you have on the portfolio page and not your index.
My navigation menue works the same on both. They all link to ID Anchors? Sorry Im not understanding how to fix it still heh.
@Alex What you are doing is kind of a hack. It is relying on the coincidental fact that the css selector by ID starts with a hash, and so do internal anchors in a URI. This is not a big problem because it works, but you need to check that the referenced element exists before trying to do stuff on it. In this case, simply checking "if($target && target) {" should do that for you, but if you want a more robust solution, you need to use something like this: paulund.co.uk/smooth-scroll-to-internal-links-with-jquery
I could kiss you matt! Thank you so much. Ive spent the better part of a day trying to hack this to get it to work heh. Thank you, my net trawling skills have failed me that code was perfect. Thank you so much again!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.