• Hey there!

    I am using your plugin, which is working like a charm. Now I’ve added some jQuery code for smooth scrolling to anchors to a specific page on my site and I’m receiving errors. I tried to figure out, how to avoid this, but didn’t get any further. So maybe you could help me?! 🙂

    I’m using latest version of your plugin and I’m running this code:

    jQuery(document).ready(function($){
    		if(window.location.href.indexOf("tradition") > -1) {
    			$('a[href^="#"]').on('click',function (e) {
    				e.preventDefault();
    
    				var target = this.hash,
    				$target = $(target);
    
    				$('html, body').stop().animate({
    					'scrollTop': $target.offset().top
    				}, 900, 'swing');
    			});
    		}
    	});

    which only comes to effect, when “tradition” page is being loaded.

    While your plugin is working on the other pages perfectly fine, debugger returns this error: TypeError: $target.offset(...) is undefined when my code gets loaded and the plugin stops working.

    Any idea? :/

    Cheers!

    https://ww.wp.xz.cn/plugins/dynamic-to-top/

Viewing 1 replies (of 1 total)
  • Anonymous User 7698158

    (@anonymized-7698158)

    Hi,
    I had the same problem and I added a check to test if target had a value before running the code. My code is similar to yours – so that might work for you. That worked and bypassed this to allow the Dynamic plugin to work.

    if (target.length) {
    			$('html, body').stop().animate({
    				'scrollTop': $target.offset().top
    			}, 900, 'swing', function () {
    				window.location.hash = target;
    			});
    		}
Viewing 1 replies (of 1 total)

The topic ‘Conflict with other jQuery code’ is closed to new replies.