问题
I want to add deeplinking into flexslider..
The ability to click on a specific link:
<a href="#contact">whatever text..</a>
id, and it will take me to the specific slider li. Is this possible? e.g.
<ul>
<li id="title">...</li>
<li id="title2">...</li>
<li id="title3">...</li>
<li id="contact">...</li>
</ul>
-Neil
回答1:
Use the JavaScript's window.location.hash
. Use any of these:
var hash = $(this).attr('href').split('#')[1];
var hash = $(this).attr('href').replace(/^.*?#/,'');
var hash = $(this).attr('href').substr(test.indexOf('#')+1);
var hash = $(this).attr('href').match(/#(.*$)/)[1];
Use this code then:
var hash = window.location.hash;
$("#" + hash).show();
This will show the particular div
from the given URL. You can take this code as a reference:
JavaScript
$(document).ready(function(){
var hash = window.location.hash;
$("#hash").html(hash);
$("div").removeClass("selected");
$(hash).addClass("selected");
});
HTML
<a href="#one">One</a>
<a href="#two">Two</a>
<div id="one">One</div>
<div id="two">Two</div>
<div id="hash"></div>
CSS
.selected {background: #ff0;}
Fiddle: http://jsfiddle.net/praveenscience/F2whf/
来源:https://stackoverflow.com/questions/19561800/deeplinking-within-flexslider-or-any-slider