0

I have a really basic bit of JavaScript that I'm struggling with. It lets the user click a link and the viewport then moves down to that point in the page. Here is my current tinker: https://tinker.io/8e585/16.

I would like it to work so when the user clicks the image^ under 'Test 2' it would scroll down AND open up the text within 'Test 2' at the same time?

Many thanks for any pointers with this.

 

^ <h3 class="head"><a href="javascript:slideonlyone('newboxes7');"><img src="/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png" class="small" style="position:absolute;margin-left: 241px;margin-top: 128px;" /><img src="/wp-content/themes/boilerplate/images/sector-21.jpg"></a></h3>

2 Answers 2

2

You can call the $(this).scrollTop() function and define scrollTop event

$(this).scrollTop(function(){
    //your code to do both tasks
)};

Hope it helps :)

Update:

function slideonlyone(thechosenone) {
     $('.newboxes2').each(function(index) {
          if (this.id == thechosenone) {
                if($(this).is('.active') )
                   $(this).removeClass('active').slideUp(600);
              else 
              $(this).addClass('active').slideDown(200);
          }
          else              
               $(this).removeClass('active').slideUp(600);

         if($(this).is('.active') )
             jQuery(this).parent('.grid_4').children().find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_onstate.png');
         else
             jQuery(this).parent('.grid_4').children().find('img.small').attr('src', '/wp-content/themes/boilerplate/images/image_corner_btn_offstate.png');
     });
}

$('#box1 h2').click(function () {   
    $('html, body').animate({
         scrollTop: $('#box2').offset().top}, 'slow');
    slideonlyone(thechosenone);
    return false;
});
$('#box2 h2').click(function () {   
    $('html, body').animate({
         scrollTop: $('#box1').offset().top}, 'slow');
    slideonlyone(thechosenone);
    return false;
});
Sign up to request clarification or add additional context in comments.

5 Comments

Ooooh - brill! I'll give it a wee tinker just now. Back in 2 :)
OK, I've given that a go, but it doesn't seem to be playing ball. Here's me Tinker :-) tinker.io/8e585/17 Thanks for any pointers.
you got a little bit problem with the syntax. Try the updated code in your tinker.
Thanks for this, I've updated again: tinker.io/8e585/18 but it still doesn't seem to be working :-/
se the updated code. its a bit static, but you can get the idea. and don't need to manipulate the scroll event for this
0

ANSWER: https://tinker.io/8e585/19 :-D

I basically used $("#box2 h3 a").click(function () {.

Comments

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.