I want to开发者_如何学Python use this page scrolling technique from js.
http://www.xfunda.com/index.php?view=article&id=55%3Ajavascript-page-scroll-scroll-a-web-page-from-bottom-to-top-smoothly&option=com_content&Itemid=75
But what if the user doesnt have js
<p><a href="javascript:void(0)" onclick="goto_top()"><img src="/goto_top.gif" alt="Top" border="0" /></a></p>
but what if I want to just user the anchors ont he page for a user who doesnt have js turned on for the nice scrolling effect?
To use anchors, change javascript:void(0)
to #anchor_name
and make sure that goto_top()
or whatever your click handler is returns false
.
The key way to implement that is to use the anchors #top within the hyperlink, and if the user has javascript enabled, then you use JS code to modify the link. That's the unobtrusive javascript approach.
var element = document.getElementById("alink");
element.href = "javascript:void(0);"; //changes from #top
element.onclick = function() { goto_top(); };
That way, if JS is disabled, the #top reference stays in the link, but if JS is enabled, it will replace and use the nice scrolling effect.
精彩评论