javascript - Can't get page to scroll to top on click -
javascript - Can't get page to scroll to top on click -
so i'm migrating webpage basic construction wordpress , 1 of pages has table of contents. toc has plus signs allow expand different areas of toc , when click on links , not, body scrolls properly, however, actual html tag of entire page not scrolling up.
so basically, rough mock of page laid out like
<html overflow-y: scroll; margin-left/right: auto; width: 1235px;> <body overflow-y: scroll> ...primary content here centered html css </body> </html>
so basically, clicking plus signs uses href tags set body scroll window, however, since html document isn't scrolling well, doesn't align page header of section clicked navigate to. here code openclose function utilized plus signs:
function openclose(thename, menuarray, theid) { for(var i=0; < menuarray.length; i++) { if (menuarray[i] == theid) { if (document.getelementbyid(theid).style.display == "block") { document.getelementbyid(theid).style.display = "none"; document.getelementbyid("tick_"+menuarray[i]).innerhtml = "+"; erasecookie(thename); } else { document.getelementbyid(theid).style.display = "block"; document.getelementbyid("tick_"+menuarray[i]).innerhtml = "-"; newcookie(thename,menuarray[i],exp); } } else { document.getelementbyid(menuarray[i]).style.display = "none"; document.getelementbyid("tick_"+menuarray[i]).innerhtml = "+"; } } $(window).scrolltop(0); // 1 of many examples }
the scrolltop
1 of many examples i've tried, html document scroll top, however, nil seems anything. i'm not trying scroll body, want scroll master vertical scroll bar. figured in openclose on click function set such function @ end scrolls entire document after navigates position defined on click event. again, nil happens. missing simple?
i googled , found other page how scroll top of page jquery? none of examples work.
you can't utilize $ sign jquery in wordpress unless define it. swop word "jquery" in each place utilize $, utilize "jquery". there other ways if safe mode jquery.
also utilize console - chrome/ firefox = right click on page element , select "inspect element" see console on top menu of window appears. display js errors. in code above see "undefined not function" classic jquery not loaded error (or have conflict $ symbol , need used safe mode jquery) , see "unexpected" error missing brackets.
function openclose(thename, menuarray, theid) { for(var i=0; < menuarray.length; i++) { if (menuarray[i] == theid) { if (document.getelementbyid(theid).style.display == "block") { document.getelementbyid(theid).style.display = "none"; document.getelementbyid("tick_"+menuarray[i]).innerhtml = "+"; erasecookie(thename); } else { document.getelementbyid(theid).style.display = "block"; document.getelementbyid("tick_"+menuarray[i]).innerhtml = "-"; newcookie(thename,menuarray[i],exp); } } else { document.getelementbyid(menuarray[i]).style.display = "none"; document.getelementbyid("tick_"+menuarray[i]).innerhtml = "+"; } } jquery(window).scrolltop(); // 1 of many examples };
javascript html css wordpress
Comments
Post a Comment