jquery - Display DIV and then go to an element inside that DIV -
i trying unhide div , right after scroll down element.
i have "index" of text have list of anchor tags href'ing different id's down page, @ first sight text hidden , first display when click on 1 of index links. works fine untill scroll part.
there nothing special code far, it's mere if statement adding & removing css class depending on client action. how page automatically scroll down after div displays?
i tried solution: how go specific element on page, couldn't seem fit in own script.
if ($('#<%=paragraph.clientid%>').hasclass("readable")) { $('#<%=paragraph.clientid%>').removeclass("readable"); // readable class hides paragraphs. // run function scroll down selected element here. } else { $('#<%=paragraph.clientid%>').addclass("readable"); }
what first tried this:
(function($) { $.fn.goto = function() { $('html, body').animate({ scrolltop: $(this).offset().top + 'px' }, 'fast'); return this; // chaining... } })(jquery); function showparagraphs(elementid) { if ($('#<%=paragraph.clientid%>').hasclass("readable")) { $('#<%=paragraph.clientid%>').removeclass("readable"); scrolltoelement(elementid); } else { $('#<%=paragraph.clientid%>').addclass("readable"); } }; function scrolltoelement(elementid) { $(elementid).goto(); };
but above script didn't work. , javascript skills limited, i'm kind of lost.
any hints or awesome. thank you.
your code looks working. think thing need change in showparagraphs
function have to...
replace scrolltoelement(elementid)
scrolltoelement('#<%=paragraph.clientid%>')
...since you're pulling id
element want affect server , not passed in argument.
if doesn't it, here's working demo threw together can try implementing alternative.
Comments
Post a Comment