我正在使用页面内链接锚点来平滑地向下滚动我的页面。一切都很正常,每个链接都会悬停到相应的图像。我似乎不能让它在任何事情上工作。
这是我的HTML
<div id="scrollnav">
<ul>
<li class="scrolldot"><span><a href="#one">1</a></span></li>
<li class="scrolldot"><span><a href="#two">2</a></span></li>
<li class="scrolldot"><span><a href="#three">3</a></span></li>
<li class="scrolldot"><span><a href="#four">4</a></span></li>
<li class="scrolldot"><span><a href="#five">5</a></span></li>
<li class="scrolldot"><span><a href="#six">6</a></span></li>
</ul>
</div>这是我的CSS
#scrollnav { width: 75px; height: 150px; position: fixed; right: 0; top: 100px; z-index: 999999;}
#scrollnav ul li { height: 16px; width: 16px; padding: 0px 0px 7px 0px; }
span { text-indent: -99999px; }
.scrolldot a { display: block; height: 16px; width: 16px; background-image: url(../images/dots.png); background-repeat: no-repeat; background-position: -16px 0; }
.scrolldot a:hover { background-image: url(../images/dots.png); background-repeat: no-repeat; background-position: 0 0; }
.selected { background-color: red; }这是我要滚动到并想要激活的部分的一个示例。
<section id="one">
<div id="mainimagewrapper">
<div class="image1">
<div class="image2">
<div class="970content">
<div id="textdiv">
<h1>This is headline.</h1>
<p>This would be a description if someone wanted to write stuff here. This would be a description if someone wanted to write stuff here. This would be a description if someone wanted to write stuff here.</p>
</div>
</div>
</div>
</div>
</div>
</section> 发布于 2013-02-08 00:29:29
定义锚伪类的/*顺序*/
a, a:link, a:visited { ... css ...}
a:hover, a:visited:hover {... css ...}
a:active,a.my-active {... css ...}
a:focus {... css ...}通过这种方式,您可以为锚点上的浏览器默认操作定义样式。
在此之后,您可能需要使用javascript触发一些行为(以防浏览器由于超链接中的#hash而出现错误行为)。
使用jQuery操作来添加一些您的风格,例如。.my active切换到的onClick如果您“重新加载”页面,将不会对您有所帮助。您必须从超链接中推导出#hash,然后将其用于样式设置。
只需使用jQuery hashchange从超链接获取#hash,然后在作用域中的元素上触发一个类。
否则,如果你只需要一个插件来滚动--在打开的页面中的某个地方进行研究:http://demos.flesler.com/jquery/scrollTo/或 jquery-joyride-feature-tour-plugin。
继续
发布于 2013-02-08 00:29:36
我认为最简单的方法,不需要编写自己的jQuery脚本,就是看看Twitter Bootstrap的"Scrollspy“插件。我相信它只需要很少的配置就能提供你想要的效果。
链接:http://twitter.github.com/bootstrap/javascript.html#scrollspy
https://stackoverflow.com/questions/14755835
复制相似问题