Answer the question
In order to leave comments, you need to log in
Why doesn't scroll to an element work?
Scroll to element not working in wordpress. Although on normal html everything works.
The code:
(function ($) {
$.fn.anchorAnimate = function(options) {
var settings = $.extend({}, $.fn.anchorAnimate.defaults, options);
return this.each(function() {
var caller = this;
$(caller).click(function(event) {
event.preventDefault();
var elementClick = $(caller).attr("href");
var destination = $(elementClick).offset().top -60;
$("html:not(:animated), body:not(:animated)").animate({ scrollTop: destination}, settings.speed, function() {
if(0 === settings.offset) {
window.location.hash = elementClick;
}
});
return false;
});
});
};
$.fn.anchorAnimate.defaults = {
speed: 1000
};
}(jQuery));
$(document).ready(function(){
$("a.slow-scroll").anchorAnimate();
$(window).scrollTop(0);
var hash = window.location.hash;
hash && $('a.slow-scroll[href="' +hash+ '"]').click();
});
<li><a class="slow-scroll" href="<?php echo get_home_url(); ?>#company">company</a></li>
Uncaught Error: Syntax error, unrecognized expression: http://localhost/aestetic#company
Answer the question
In order to leave comments, you need to log in
var elementClick = $(caller).attr("href");
var destination = $(elementClick).offset().top -60;
jQuery('http://localhost/aestetic#company');
Uncaught Error: Syntax error, unrecognized expression: http://localhost/aestetic#company(…)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question