• Resolved lewisp91

    (@lewisp91)


    Hi Tobias,

    I used your code in this thread to make an entire row clickable:
    https://wordpress.org/support/topic/make-row-clickable/?replies=18#post-4655516

    It works great, but then I applied some smooth scroll jquery for anchor links:

    <script type="text/javascript">
    jQuery(document).ready(function($){
    	$(".smooth-scroll").click(function(event){		
    		event.preventDefault();
    		$('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
    	});
    });
    </script>

    I applied the class to a link in my table row and the smooth scroll works great – but ONLY if I click the actual text link.

    Clicking the row does jump down the page, but the smooth scroll is not applied.

    How would I fix that? Is it possible?

    Thanks,
    Lewis

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    Yes, this should be possible. You’d have to merge this code into the other code from the link.
    Unfortunately, as this is more of a pure JavaScript question, it’s beyond what I can help with at the moment, due to time constraints. Sorry 🙁

    Regards,
    Tobias

    Thread Starter lewisp91

    (@lewisp91)

    Ahh, no problem. I understand.

    Can I follow up with you next week? Or is this something you wont be able to help me with period?

    Thanks Tobias!

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    it would be great if you could try yourself first. You’ll basically just have to understand the logic behind the code, and how jQuery and its events work.
    Then, it should be rather straightforward to apply the commands from your code to the code from the existing post.

    Regards,
    Tobias

    Thread Starter lewisp91

    (@lewisp91)

    Thank you so much for the quick reply, Tobias!

    Unfortunately, I have very minimal understanding of Javascript (or anything outside of HTML and CSS for that matter). That code is not mine, I Googled it :/

    If you can’t help me, I’ll try posting this question on another forum. Either way, I really appreciate your help.

    Can you recommend anywhere that I might be able to get assistance with this?

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    after taking another look, it’s actually simpler than I thought:

    <script type="text/javascript">
    jQuery(document).ready(function($){
    	$('.smooth-scroll').click(function(event){		
    		event.preventDefault();
    		$('html,body').animate({scrollTop:$(this.hash).offset().top}, 500);
    	} );
    
      $('.tablepress-id-1').on( 'click', 'tr', function() {
        $(this).find('.smooth-scroll').last().click();
      } );
    } );
    </script>

    With this, a click on a row in table 1 (you’d have to adjust that table ID in the code, if necessary), would implicitly trigger a click on the last .smooth-scroll link in that row.

    Regards,
    Tobias

    Thread Starter lewisp91

    (@lewisp91)

    Thank you Tobias!!

    You are awesome. Really, really appreciate it!

    It’s working great except once it’s triggered, I can no longer scroll up or down the page. It just locks me to the anchor point.

    Is that an issue on my end, or the code?

    Thread Starter lewisp91

    (@lewisp91)

    Here’s a quick recording of the issue: http://imgur.com/A4kvgkb

    • This reply was modified 8 years, 10 months ago by lewisp91.
    • This reply was modified 8 years, 10 months ago by lewisp91.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    that sounds strange. I can’t see any particular reason for that in the code.
    Does this also happen when you directly click the link (and not the row).
    I can only assume that this is caused by the smooth-scroll JavaScript code itself.

    Regards,
    Tobias

    Thread Starter lewisp91

    (@lewisp91)

    Hi Tobias,

    Yes, it also happens when I click the link itself. I’ve reverted to the previous for now, but if you have any ideas, please let me know 🙂

    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    ok, but does it happen with just your initial code as well?

    Regards,
    Tobias

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Row link with smooth scroll’ is closed to new replies.